ffmpeg-python wrapper ffmpeg.run() getting FILENOTFOUNDERROR - python-3.x

I'm trying to figure out and learn how to use the ffmpeg-python wrapper and am getting a file not found error. both the mp4 file I'm trying to process and the python file are both in a folder on my desktop. I'm not sure if I'm using it correctly here.
I'm running windows 10 32bit, python 3.6 and have ffmpeg-python 0.16.0 installed. Is there additional packages I need installed in order for this to work? I tried the same code on my 64 bit windows 10 desktop and got the same error.
import ffmpeg
videoInput = ffmpeg.input('vid.mp4')
videoOutput = videoInput.output('test.avi')
videoOutput.run()
This is the error that I get in python shell
Traceback (most recent call last):
File "C:\Users\geral\Desktop\PythonPrograms\ffmpegexample.py", line 7, in <module>
videoOutput.run()
File "C:\Users\geral\AppData\Local\Programs\Python\Python36-32\lib\site-packages\ffmpeg\_run.py", line 300, in run
overwrite_output=overwrite_output,
File "C:\Users\geral\AppData\Local\Programs\Python\Python36-32\lib\site-packages\ffmpeg\_run.py", line 272, in run_async
args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream)
File "C:\Users\geral\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\geral\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

Well I figured it out and it was actually really quite simple. Hopefully this will help anyone who is new to ffmpeg or ffmpeg-python.
After reading through the traceback: Probably 100 times. I realised that ffmpeg probably wasn't packaged with ffmpeg-python and I never installed ffmpeg myself. So I simply installed ffmpeg using This Installation Guide and everything worked.
I Probably have this memorised by now, Ive read it enough times.
ffmpeg-python API Reference
So Long story short you must have ffmpeg installed before ffmpeg-python will work.

Related

gdbm error 22 when performing Python shelve open

Doing a simple shelve.open will give the following error:
>>> shelve.open('foo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/usr/lib/python3.6/shelve.py", line 227, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "/usr/lib/python3.6/dbm/__init__.py", line 94, in open
return mod.open(file, flag, mode)
_gdbm.error: [Errno 22] Invalid argument
I've only come across one related search result to this issue: https://github.com/pydanny/cookiecutter-django/issues/1793#issuecomment-440406112
I got exactly the same error on a Vagrant dev environment. Celery uses dbm for persistent storage, which is built on top of the gdbm C library. Some testing has revealed that this works when creating or opening files on a native filesystem but not on a mounted filesystem.
I'm running this under a Vagrant Ubuntu box in MacOS so it makes sense. I have also run the same box under Windows 10 and this issue doesn't crop up. Any clues for a fix?
I had the same issue and couldn't find any help online until I came across this post
https://github.com/we45/ThreatPlaybook/issues/11
creating a new virtual environment worked for me

Reading .doc files in python on windows 10

Note: This was flagged as a potential duplicate of this, but the point of my question is that using textract doesn't work. I am looking either for (a) a way to get textract to work on windows 10 or (b) an alternate solution.
I am building a system that needs to read various types of files. I have set up pdfminer to read the .pdfs, and based on the process outlined here I installed textract, and I can now also read .docx files. However textract relies on antiword for reading .doc files and I cannot get this to work, even after following the directions here I could not find and install a working version of antiword. I do not have microsoft word installed on my machine, and I am running windows 10 with python 3.6.5. Is there any other way to read .doc files?
Here is the bug when running textract.process('d.doc') (ignore the first error, the file is definitely there):
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\utils.py", line 84, in run
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\__init__.py", line 77, in process
return parser.process(filename, encoding, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\utils.py", line 46, in process
byte_string = self.extract(filename, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\doc_parser.py", line 9, in extract
stdout, stderr = self.run(['antiword', filename])
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\utils.py", line 91, in run
' '.join(args), 127, '', '',
textract.exceptions.ShellError: The command antiword d.doc failed with exit code 127
From the 'Windows installation problem' series: https://github.com/deanmalmgren/textract/issues/194#issuecomment-507243521
After following the steps to 'install' antiword, I was facing the same problem as yours.
Restarting windows after setting up the environment path variable entirely solved this exact error message for me. (This was the last error I was facing for handling .doc files with textract)
Installation instructions extracted from https://github.com/deanmalmgren/textract/issues/194#issuecomment-506065817
"Install Antiword
(I followed Reading .doc file in Python using antiword in Windows (also .docx))
Go to https://www.softpedia.com/get/Office-tools/Other-Office-Tools/Antiword.shtml
Extract to c:\antiword (yes it's required to be in the root directory)
Add location to path like we did tesseract-ocr [basically add c:\antiword to the system path (environment variable)]"
I was able to get part of the text using olefile, but olefile ultimately only handles bytes and does not handle the encoding of Word .doc files. The solution is to use LibreOffice, see my other question here

VirtualEnv and python-embed

I have a Windows machine running many apps using Python 2. I want to add a new program I wrote using Python 3. To make sure I don't screw anything up, I wanted to use a Virtualenv with Python 3 embedded (Python 3 embed amd64).
So I extracted the embedded python 3 and tried running virualenv with the --python option enabled.
I tried running the virtualenv
python -m virtualenv --python E:\Projects\python3-embed\python.exe E:\Projects\Virtual\
And I got this error:
Running virtualenv with interpreter E:\Projects\python3-embed\python.exe
Using base prefix 'E:\\Projects\\python3-embed'
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\virtualenv.py", line 2328, in <module>
main()
File "C:\Python27\lib\site-packages\virtualenv.py", line 713, in main
symlink=options.symlink)
File "C:\Python27\lib\site-packages\virtualenv.py", line 925, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "C:\Python27\lib\site-packages\virtualenv.py", line 1147, in install_python
writefile(site_filename_dst, SITE_PY)
File "C:\Python27\lib\site-packages\virtualenv.py", line 362, in writefile
with open(dest, 'wb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'E:\\Projects\\Virtual\\python36.zip\\site.py'
I am not entirely sure how can I fix this error. There is a site.pyd file in python36.zip but it seems that virtualenv can't use it.
Sorry in advance
I knew this is not the answer you meant to ask for, but I tried hard that (our) way, and got this solution at last.
TL;DR
Update on 17 December 2021
The download page has been moved to https://winpython.github.io/
, for my purpose, I will download Winpython64-3.10.0.1dot.exe for now. Please don't forget to verify the checksum for the executable package.
End of the update on 17 December 2021
Use the portable installer with postfix "Zero" from WinPython
WinPython64-3.7.0.2Zero.exe(64 bit version, YOU want this)
WinPython32-3.7.0.2Zero.exe(32 bit version)
The Too Long version
What I tried
Yes, I downloaded the python-3.7.0-embed-amd64.zip from this page
Yes, I set it up according to instructions in this page
Yes, it worked as a python interpreter
D:\temp\test>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
>>>
Yes, I installed the package virtualenv
D:\temp\test>virtualenv --version
16.0.0
Then, boom (where you asked)
D:\temp\test>virtualenv ENV
Using base prefix 'd:\\portable\\python-3.7.0-embed-amd64'
Traceback (most recent call last):
File "runpy.py", line 193, in _run_module_as_main
File "runpy.py", line 85, in _run_code
File "D:\portable\python-3.7.0-embed-amd64\Scripts\virtualenv.exe\__main__.py", line 9, in <module>
File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 712, in main
symlink=options.symlink)
File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 927, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 1149, in install_python
writefile(site_filename_dst, SITE_PY)
File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 363, in writefile
with open(dest, 'wb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\temp\\test\\ENV\\python37.zip\\site.py'
Seems a problem with virtualenv, searched, got an open issue, and I don't like that long solution.
This is the end of virtualenv.
Then, I tried venv:
D:\temp\test>python -m venv venv
D:\portable\python-3.7.0-embed-amd64\python.exe: No module named venv
Yes, the "built-in module" was lost, and the document for Embedded Distribution doesn't even mention it, just something about Tcl/tk (...), pip and the Python documentation are not included.
This is the end of venv.
Well, start again from my original point
The purpose to choose Embedded Distribution is (just like SOMEBODY):
To make sure I don't screw anything up
this include "don't install anything into my unstable and oversized Windows"
but doesn't necessarily "must use the Official Embedded Distribution"
something portable and trusted is enough, yes Portable Python
but the main page says "Portable Python is not being developed anymore", and provide some choice
after some reading, I figured out, what I want is WinPython, the version with a Zero
ta-da ... That's it.
Something about Embedded Distribution (from official document)
The embedded distribution is a ZIP file containing a minimal Python environment. It is intended for acting as part of another application, rather than being directly accessed by end-users.
The embedded distribution is meant to be lightweight. To install a virtual environment, follow these steps.
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
Once these steps are done, proceed with the recommended approach and create a virtual environment using the command below. The --system-site-packages is typically used to bring a non embedded distribution packages already in the python install into the virtual environment, but since this is embedded, you can omit. But it won't hurt to have it.
python -m venv --system-site-packages C:\Python\python-3.7.9-embed-amd64\py37venv

[ Python 2.7 ]Package program with Pynsist

I am packaging a Python 2.7 program with the lastest version of Pynsist.
I've created an installer.cfg file following this example.
But when I try to package my application running
pynsist installer.cgf
into the application folder it comes up with
Copying Python installer to build directory
PyLauncher MSI already in build directory.
Copying packages into build directory...
Traceback (most recent call last):
File "/usr/local/bin/pynsist", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/nsist/__init__.py", line 540, in main
InstallerBuilder(**args).run(makensis=(not options.no_makensis))
File "/usr/local/lib/python2.7/dist-packages/nsist/__init__.py", line 495, in run
self.prepare_packages()
File "/usr/local/lib/python2.7/dist-packages/nsist/__init__.py", line 381, in prepare_packages
py_version=self.py_version, exclude=self.exclude)
File "/usr/local/lib/python2.7/dist-packages/nsist/copymodules.py", line 224, in copy_modules
mc.copy(modname, target, exclude)
File "/usr/local/lib/python2.7/dist-packages/nsist/copymodules.py", line 195, in copy
check_package_for_ext_mods(path, self.py_version)
File "/usr/local/lib/python2.7/dist-packages/nsist/copymodules.py", line 41, in check_package_for_ext_mods
check_ext_mod(os.path.join(path, dirpath, filename), target_python)
File "/usr/local/lib/python2.7/dist-packages/nsist/copymodules.py", line 30, in check_ext_mod
raise ExtensionModuleMismatch(extensionmod_errmsg % ('Windows', path))
nsist.copymodules.ExtensionModuleMismatch: Found an extension module that will not be usable on Windows:
/usr/lib/python2.7/dist-packages/pygame/rwobject.so
Put Windows packages in pynsist_pkgs/ to avoid this.
So the problem I think is with Pygame.
On Google there in nothing about this, but i cannot use others programs for packaging(eg. py2exe, pyinstaller ecc...).
Thanks and sorry for the bad english
Reposting as an answer, since it worked:
If you put pygame in packages=, it tries to copy it from your computer. But on your computer that's pygame for Linux, which won't work on Windows. If you instead put pygame in the pypi_wheels= bit of the config file, Pynsist will take care of downloading a Windows version for you.
Have a look at the pygame example in the Pynsist repository.
Most packages don't have this problem because they only contain Python code, which is the same files on all platforms. Pygame has compiled modules, which have to be compiled for the right platform.

Error in using pyexiv2 metadata.read() method

I am trying to follow the tutorials in the pyexiv2 tutorials page
But due to some unknown reasons, it refuses to run, and I thought of seeking some advice from you.
`#this is my code
import pyexiv2
metadata = pyexiv2.ImageMetadata('test.png')
metadata.read()`
when I try to run this code in the terminal, with the python interpreter, in the folder which contains the image, 'test.png', following error is given.
`Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pyexiv2/metadata.py", line 107,
in read
self.__image = self._instantiate_image(self.filename)
File "/usr/lib/python2.7/dist-packages/pyexiv2/metadata.py", line 74,
in
_instantiate_image
raise IOError(ENOENT, os.strerror(ENOENT), filename)
IOError: [Errno 2] No such file or directory: 'test.png'
`
This is my setup. I am running ubuntu 16.04LTS on virtual machine on a Mac book, with macOS sierra. Python version is 2.7.12.
I used this guide to install pyexiv2. when I inspect the /usr/local/lib folder, it shows that the libexiv2 is installed there.
What am I doing wrong here? and is there a better version of pyexiv2 to use?
I am fairly new to using python.:) and thanks in advance
This can be solved in two ways
1) Copy the file test.png in the same directory you have your python file with the code.
2) Provide a complete path. If, for example, you have test.png on your desktop, replace
metadata = pyexiv2.ImageMetadata('test.png')
with
metadata = pyexiv2.ImageMetadata('C:\\Users\\MYUSERPROFILENAME\\Desktop\\test.jpg')
where MYUSERPROFILENAME is your user profile. Hope this helps

Resources