In the process of using the ffmpeg module to edit video files i used the subprocess module
The code is as follows:
#trim bit
import subprocess
import os
seconds = "4"
mypath=os.path.abspath('trial.mp4')
subprocess.call(['ffmpeg', '-i',mypath, '-ss', seconds, 'trimmed.mp4'])
Error message:
Traceback (most recent call last):
File "C:\moviepy-master\resizer.py", line 29, in <module>
subprocess.call(['ffmpeg', '-i',mypath, '-ss', seconds, 'trimmed.mp4'])
File "C:\Python27\lib\subprocess.py", line 168, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
After looking up similar problems i understood that the module is unable to pick the video file because it needs its path, so i took the absolute path. But in spite of that the error still shows up.
The module where this code was saved and the video file trial.mp4 are in the same folder.
The WindowsError you see does not refer to the video file but to the ffmpeg executable itself. The call to subprocess.call has no idea that trimmed.mp4 is a filename you are passing. Windows knows that the first parameter ought to be an executable file and reports back to the interpreter that it can't find it.
Double-check that ffmpeg can be executed in the environment your interpreter is running in. You may either add it to your PATH or specify the full path to ffmpeg.exe.
None of the above answers worked for me.
I got it working, by opening Anaconda Navigator > CMD prompt.
conda install ffmpeg
This answer is directed at Windows users of the ffmpeg-python library since this question is the first search result for a stricter instance of the same issue.
Adding on to user2722968's answer because neither of the existing answers solved the problem for me.
As of this post, ffmpeg-python uses subprocess.Popen to run ffmpeg. Per this issue, subprocess does not look in Path when resolving names, so even if FFmpeg is installed and in your Path and you can run it from CMD/PowerShell, ffmpeg-python may not be able to use it.
My solution was to copy ffmpeg.exe into the Python environment where python.exe is. This workaround seems far from ideal but it seems to have solved the problem for me.
Most of the answers didn't work. Here is what worked for me using conda env:
pip uninstall ffmpeg-python
conda install ffmpeg
pip install ffmpeg-python
Just the conda installation gives library not found error. Didn't try uninstalling conda library either but this works.
I had the same issue!
And I FOUND A SOLUTION.
I realised, viewing all these answers that I need to install ffmpeg. I tried 'pip install ffmpeg' but that didn't work. What worked was copying the ffmpeg.exe file to the folder that python.exe is in.
Thats what someone up here mentioned. Thank you!
To download the ffmpeg.exe file, download the zip file from https://github.com/GyanD/codexffmpeg/releases/tag/2022-06-06-git-73302aa193
First Uninstall all pip libraries
pip uninstall ffmpeg
pip uninstall ffmpeg-python
Then install using conda
conda install ffmpeg
If you are going to use 'ffmpeg.exe' or its linux binary, you need this
conda install ffmpeg
Then you will call it via subprocess or os.system() in your code.
And make sure you will run a different thread to run ffmpeg code otherwise there will be a huge bottleneck in your main thread.
class SaveAll():
def init(self):
super(SaveAll, self).__init__()
def save(self):
try:
command = "ffmpeg -i {} -c copy -preset ultrafast {}"format(...)
os.system(command)
except ffmpeg.Error as e:
print (e.stout, file=sys.stderr)
print (e.stderr, file=sys.stderr)
def run(self):
self.thread= threading.Thread(target=self.save)
self.thread.start()
self.thread.join(1)
...
saver = SaveAll()
saver.start()
Related
I am trying to use librosa to analyze .wav files. I started with creating a list which stores the names of all the .wav files it detected.
data_dir = '/Users/raghav/Desktop/FSU/summer research'
audio_file = glob(data_dir + '/*.wav')
I can see the names of all the files in the list 'audio_file'. But when I load any of the audio file, it gives me file not found error.
audio, sfreq = lr.load(audio_file[0])
error output:
Traceback (most recent call last):
File "read_audio.py", line 10, in <module>
audio, sfreq = lr.load(audio_file[1])
File "/usr/local/lib/python3.7/site-packages/librosa/core/audio.py", line 119, in load
with audioread.audio_open(os.path.realpath(path)) as input_file:
File "/usr/local/lib/python3.7/site-packages/audioread/__init__.py", line 107, in audio_open
backends = available_backends()
File "/usr/local/lib/python3.7/site-packages/audioread/__init__.py", line 86, in available_backends
if ffdec.available():
File "/usr/local/lib/python3.7/site-packages/audioread/ffdec.py", line 108, in available
creationflags=PROC_FLAGS,
File "/usr/local/lib/python3.7/site-packages/audioread/ffdec.py", line 94, in popen_multiple
return subprocess.Popen(cmd, *args, **kwargs)
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'avconv': 'avconv'
Two things:
It looks like you are using Homebrew
avconv is not in your path
Assuming, you have never installed it, you should be able to solve this simply by installing it. I.e. run:
$ brew install libav
(see here)
If avconv is already installed, you probably need to look into your PATH environment and check whether it is in the path.
That said, using a system-wide Python as installed by Homebrew is a bad idea, because it does not quickly let you change Python versions and dependency sets. It all becomes one big mess within weeks.
One (among multiple) solutions for this is to use miniconda. It quickly lets you activate Python interpreters with defined dependency sets.
So to really solve the issue, I'd recommend to install miniconda and create a plain Python 3.6 environment:
$ conda create -n librosa_env python=3.6
Activate the environment:
$ source activate librosa_env
Then add the conda-forge channel (a repository that contains many libraries like librosa):
$ conda config --add channels conda-forge
Then install librosa:
$ conda install librosa
By installing librosa this way, conda should take care of all dependencies, incl. libav.
That error suggests librosa is unable to find FFMPEG executables, of which avconv is an example.
When not converting different samplerates, FFMPEG is often not needed. You can try to specify the sample size to be the original of the audio file during load()
Upgrading audioread to 2.1.8 fixed this issue for me. The bugfix can be inspected here: https://github.com/beetbox/audioread/commit/8c4e236fda38ce1d1f6dafc4715074a790e62849
I had to install FFMPEG to solve the issue.. You may follow along the link https://www.wikihow.com/Install-FFmpeg-on-Windows for the same.
Hi I am trying the python library pytesseract to extract text from image.
Please find the code:
from PIL import Image
from pytesseract import image_to_string
print image_to_string(Image.open(r'D:\new_folder\img.png'))
But the following error came:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
config=config)
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
I did not found a specific solution to this. Can anyone help me what to do. Anything more to be downloaded or from where i can download it etc..
Thanks in advance :)
I had the same trouble and quickly found the solution after reading this post:
OSError: [Errno 2] No such file or directory using pytesser
Just need to adapt it to Windows, replace the following code:
tesseract_cmd = 'tesseract'
with:
tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'
(need double \\ to escape first \ in the string)
You're getting exception because subprocess isn't able to find the binaries (tesser executable).
The installation is a 3 step process:
1.Download/Install system level libs/binaries:
For various OS here's the help. For MacOS you can directly install it using brew.
Install Google Tesseract OCR (additional info how to install the
engine on Linux, Mac OSX and Windows). You must be able to invoke the
tesseract command as tesseract. If this isn’t the case, for example
because tesseract isn’t in your PATH, you will have to change the
“tesseract_cmd” variable at the top of tesseract.py. Under
Debian/Ubuntu you can use the package tesseract-ocr. For Mac OS users.
please install homebrew package tesseract.
For Windows:
An installer for the old version 3.02 is available for Windows from
our download page. This includes the English training data. If you
want to use another language, download the appropriate training data,
unpack it using 7-zip, and copy the .traineddata file into the
'tessdata' directory, probably C:\Program Files\Tesseract-OCR\tessdata.
To access tesseract-OCR from any location you may have to add the
directory where the tesseract-OCR binaries are located to the Path
variables, probably C:\Program Files\Tesseract-OCR.
Can download the .exe from here.
2.Install Python package
pip install pytesseract
3.Finally, you need to have tesseract binary in you PATH.
Or, you can set it at run-time:
import pytesseract
pytesseract.pytesseract.tesseract_cmd = '<path-to-tesseract-bin>'
For Windows:
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
The above line will make it work temporarily, for permanent solution add the tesseract.exe to the PATH - such as PATH=%PATH%;"C:\Program Files (x86)\Tesseract-OCR".
Beside that make sure that TESSDATA_PREFIX Windows environment variable is set to the directory, containing tessdata directory. For example:
TESSDATA_PREFIX=C:\Program Files (x86)\Tesseract-OCR
i.e. tessdata location is: C:\Program Files (x86)\Tesseract-OCR\tessdata
Your example:
from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
print pytesseract.image_to_string(Image.open(r'D:\new_folder\img.png'))
You need Tesseract OCR engine ("Tesseract.exe") installed in your machine. If the path is not configured in your machine, provide complete path in pytesseract.py(tesseract.py).
README
Install Google Tesseract OCR (additional info how to install the engine on Linux, Mac OSX and Windows). You must be able to invoke the tesseract command as tesseract. If this isn't the case, for example because tesseract isn't in your PATH, you will have to change the "tesseract_cmd" variable at the top of tesseract.py. Under Debian/Ubuntu you can use the package tesseract-ocr. For Mac OS users. please install homebrew package tesseract.
Another thread
I have also faced the same problem regarding pytesseract.
I would suggest you to work in linux environment, to solve such errors.
Do the following commands in linux:
pip install pytesseract
sudo apt-get update
sudo apt-get install pytesseract-ocr
Hope this will do the work..
I'm trying to execute a call to an unofficial Instagram API python library, after several errors for dependencies needed I fixed, I'm stuck at this one.
File "C:\Users\Pablo\Desktop\txts_pys_phps_programacion\Instagram-API-python-master\InstagramAPI.py", line 15, in <module>
from moviepy.editor import VideoFileClip
File "C:\Python27\lib\site-packages\moviepy\editor.py", line 22, in <module>
from .video.io.VideoFileClip import VideoFileClip
File "C:\Python27\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 3, in <module>
from moviepy.video.VideoClip import VideoClip
File "C:\Python27\lib\site-packages\moviepy\video\VideoClip.py", line 20, in <module>
from .io.ffmpeg_writer import ffmpeg_write_image, ffmpeg_write_video
File "C:\Python27\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 15, in <module>
from moviepy.config import get_setting
File "C:\Python27\lib\site-packages\moviepy\config.py", line 38, in <module>
FFMPEG_BINARY = get_exe()
File "C:\Python27\lib\site-packages\imageio\plugins\ffmpeg.py", line 86, in get_exe
raise NeedDownloadError('Need ffmpeg exe. '
NeedDownloadError: Need ffmpeg exe. You can download it by calling:
imageio.plugins.ffmpeg.download()
Those final two lines in the error messages provide a valuable clue, and I installed moviepy only today so I remember a remedy.
NeedDownloadError: Need ffmpeg exe. You can download it by calling:
imageio.plugins.ffmpeg.download()
First (sudo) pip install imageio, if necessary.
Now: import imageio and then imageio.plugins.ffmpeg.download().
If you are using Ubuntu just try:
sudo apt-get install ffmpeg
Else if you are using Windows just try to change ffmpeg.py 82th line from auto=False to auto=True
It will automatically download ffmpeg to the correct path once. Then import imageio and write down imageio.plugins.ffmpeg.download()
Will work.
This package relies on the ffmpeg executable to be in the PATH.
So just download it, install it somewhere, and add installation directory to PATH. make sure it can be accessed by typing:
ffmpeg
from the command line.
For anyone using a mac do this.
pip install imageio (if not already installed).
Then create a .py file (python script).
In this file write this:
import imageio
imageio.plugins.ffmpeg.download()
Run this script in the terminal (i.e "python (insert .py filename here)" )
It installs FFmpeg in a directory that should be automatically added to your path. If not, add it to your path.
Then type
ffmpeg
to make sure it's installed in your path.
At Windows, I'd fix this that way:
Manual download ffmpg from github
In the Lib\site-packages\imageio\plugins\ffmpeg.py file, change
exe = get_remote_file('ffmpeg/' + FNAME_PER_PLATFORM[plat], auto=False)
to
exe = "PATH_WITH_FFMPG\\ffmpeg.win32.exe"
on mac,
this is the best way to install ffmpeg.
Open terminal and type.
$ brew install ffmpeg
you will be seeing it get installed.
==> Installing dependencies for ffmpeg: lame, x264, xvid
I am facing these issues. Can you help me with the same ?
Why am I seeing this error ? Do I have to add anything in the requirements.txt file ?
>>> import git
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
import git
File "git\__init__.py", line 29, in <module>
_init_externals()
File "git\__init__.py", line 23, in _init_externals
raise ImportError("'gitdb' could not be found in your PYTHONPATH")
ImportError: 'gitdb' could not be found in your PYTHONPATH
>>> from git import Repo
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
from git import Repo
File "git\__init__.py", line 29, in <module>
_init_externals()
File "git\__init__.py", line 23, in _init_externals
raise ImportError("'gitdb' could not be found in your PYTHONPATH")
ImportError: 'gitdb' could not be found in your PYTHONPATH
I already had gitdb and smmap installed so I had to reinstall them.
You can reinstall them by running the following command in your terminal:
pip3 install --upgrade --force-reinstall gitdb; pip3 install --upgrade --force-reinstall smmap
I also got the message ImportError: 'gitdb' could not be found in your PYTHONPATH (when trying to use GitPython).BUT I had gitdb already installed!
Thanks to this hint I figured out that gitdb silently failed because it was missing smmap.
So I installed this and it worked.
You need to install gitdb package.
$ sudo easy_install gitdb
I had the same problem. However, gitdb and smmap were already installed by pip. As I used brew to install python and its dependencies on my mac, when I checked brew doctor command, it said that my /usr/local/sbin directory is not in my PATH. So I added it to my PATH (though it didn't have anything to do with the python) and everything worked out eventually.
MS Windows Versions of this problem can occur because of the order of Python versions in your system PATH, as it did for me. I did not realize that when I installed another program, it installed a newer version of Python for its own usage, and it appended my system PATH with the address to the newer version. I noticed it when I looked at the PATH variable and found two versions of Python being called. Windows uses the first it finds, and if the first doesn't match what your program expects, it gets confused and can't find the right path to the module. This is what I did to resolve it:
To check: an easy way to test if this is your problem is to see if the paths separated by semicolons are in the right order. That can be seen in the System Variables of Windows or by printing your PATH variable in your CMD shell like in this example:
C:> path
PATH=C:\Program Files (x86)\Python37-32\Scripts;C:\Program Files (x86)\Python37-32;C:\Program Files\Python38\Scripts;C:\WINDOWS
Temporary solution:
To see if it is going to fix your computer, change it in your CMD window. Your variable change will be discarded when the window is closed. One way to do this test is to copy the paths, move the Python references to the order they are needed, and write it back:
C:> set path = C:\WINDOWS;C:\Program Files (x86)\Python37-32;C:\Program Files\Python38\Scripts;C:\Program Files (x86)\Python37-32\Scripts\
Then run the Python program to see if this was your problem. Note that this is only an example; do not copy & paste it. Your path is customized for the programs on your computer.
Permanent solution: If the above test resolves your problem, you must change your System Variables to make the change permanent. For me that usually requires a reboot afterwards in order to make the variables appear in all new windows.
I'm using windows 8.1 64 bit
my code
import pdb
from moviepy.editor import *
clip = VideoFileClip(".\\a.mp4")
clip.write_gif('.\\aasda.gif')
the exception is at write_gif method
Traceback (most recent call last):
File "C:\abi\youtubetogif_project\test.py", line 5, in <module>
clip.write_gif('G:\\abi\\aasda.gif')
File "<string>", line 2, in write_gif
File "C:\Python34\lib\site-packages\moviepy-0.2.1.8.12-py3.4.egg\moviepy\decorators.py", line 49, in requires_duration
return f(clip, *a, **k)
File "C:\Python34\lib\site-packages\moviepy-0.2.1.8.12-py3.4.egg\moviepy\video\VideoClip.py", line 435, in write_gif
dispose= dispose, colors=colors)
File "<string>", line 2, in write_gif
File "C:\Python34\lib\site-packages\moviepy-0.2.1.8.12-py3.4.egg\moviepy\decorators.py", line 49, in requires_duration
return f(clip, *a, **k)
File "C:\Python34\lib\site-packages\moviepy-0.2.1.8.12-py3.4.egg\moviepy\video\io\gif_writers.py", line 186, in write_gif
stdout=sp.PIPE)
File "C:\Python34\lib\subprocess.py", line 848, in __init__
restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1104, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
I moved the script to another folder and partition, running moviepy dependancies and python as admin, turning off UAC still gives me error
I've run into this as well, solution is usually to be sure to run the program as an administrator (right click, run as administrator.)
Sometimes it occurs when some installations are not completed correctly, the process is stuck, or a file is still opened. So, when you try to run the installation again and the installation requires deleting, you can see the aforementioned error. In my case, shutting down the python processes and command prompt utilization helped.
this resolved my problem
Click on the search button in the taskbar and type “cmd”. Right-click on the Command Prompt and select Run as Administrator
pip install pydirectory
Solution on windows : restarted docker
On windows I used --use-container option during sam build
So, in order to fix stuck process, I've restarted docker
I got the same error when an imported library was trying to create a directory at path "./logs/".
It turns out that the library was trying to create it at the wrong location, i.e. inside the folder of my python interpreter instead of the base project directory. I solved the issue by setting the "Working directory" path to my project folder inside the "Run Configurations" menu of PyCharm. If instead you're using the terminal to run your code, maybe you just need to move inside the project folder before running it.
If you're encountering this in Jupyter/Jupyerlab while trying to pip install foo, you can sometimes work around it by using !python -m pip install foo instead.
On Windows, for me, it looked like at some point I'd set the folder to read-only.
Not really sure when, possibly during some mount failure on my Linux boot, but recursively clearing that flag helped.
I know it is pretty old and a couple of fellows has given the abstract answer to it.
But this is how I solved this problem on my machine. (Thanks #DevLoverUmar and #Vladyslav Didenko)
pip install gym --user
This might happen when the working directory path is different from the where the file is present . For example while running files and importing them in Spyder3 I have to check the working directory .
Maybe you wrongly set permission on python3. For instance if for the file permission is set like
`os.chmod('spam.txt', 0777)` --> This will lead to SyntaxError
This syntax was used in Python2. Now if you change like:
os.chmod('spam.txt', 777) --> This is still worst!! Your permission will be set wrongly since are not on "octal" but on decimal.
Afterwards you will get permission Error if you try for instance to remove the file:
PermissionError: [WinError 5] Access is denied:
Solution for python3 is quite easy:
os.chmod('spam.txt', 0o777) --> The syntax is now ZERO and o "0o"