MoviePY can't detect ImageMagick binary on Windows - python

I just got myself a new laptop, wanted to setup MoviePY on that new Windows 64x (Python3.7.0) machine. I triple checked everything but when it comes to text part of my code, it throws that error at me;
OSError: MoviePy Error: creation of None failed because of the following error:
OSError: [WinError 6] The handle is invalid
"ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect"
My config_defaults.py file;
import os
FFMPEG_BINARY = os.getenv('FFMPEG_BINARY', 'ffmpeg-imageio')
#IMAGEMAGICK_BINARY = os.getenv('IMAGEMAGICK_BINARY', 'auto-detect')
IMAGEMAGICK_BINARY = "C:\\Program Files\\ImageMagick-7.0.8-Q16\\magick.exe"
The path is correct and both magick.exe and convert.exe exist in that path. I'm also sure ImageMagick is properly installed. When I type convert in cmd, it prints "ImageMagick 7.0.8 Q16 x64" and bunch of other stuff.
What am I missing here?

I had the same error as you but my problem was that I did not properly installed ImageMagick : in the installation wizard you need to check "install legacy utilities".
So I reinstalled it, checked this box and it worked.
Here is a screenshot of the page I am talking about :

Take the comment from the top line, and instead of auto-detect put the path and put the name convert.
IMAGEMAGICK_BINARY = os.getenv ('IMAGEMAGICK_BINARY', 'C:\Program Files\ImageMagick-7.0.8-Q16\convert.exe')

For windows users,
Change line 54 in config_defaults.py wherever moviepy library is installed
It can be in C:/users/anaconda/lib/site-packages if you are using anaconda
IMAGEMAGICK_BINARY = os.getenv('IMAGEMAGICK_BINARY', 'C:\Program Files\ImageMagick-7.0.11-Q16-HDRI\magick.exe')
will work

I had the same problem and it got fixed thanks to this comment.
from moviepy.config import change_settings
change_settings({"IMAGEMAGICK_BINARY": r"C:\\Program Files\\ImageMagick-7.0.8-Q16\\magick.exe"})
This solved the problem for me.

Related

ImportError: libbz2.so.1.0: cannot open shared object file: No such file or directory || ONLY IN PYCHARM

I am using PyCharm on a fresh Linux installation. Every time I try to import librosa, pandas (or some other packages) I get the error:
ImportError: libbz2.so.1.0: cannot open shared object file: No such file or directory
The weird thing is that it works without any problems in the terminal. In PyCharm, however, it does not work.
I already tried to add the directory under which libbz2.so.1.0 is installed (/usr/lib/x86_64-linux-gnu) to the LD_LIBRARY_PATH.
I did that in my PyCharm run configuration and in the .bashrc.
Clearly, it is installed correctly in my packages, otherwise, I couldn't use it in the terminal so I don't know what else I can do.
Fixed it...
I initially installed pycharm via the software manager of linux mint.
Apparently, that was a mistake.
The error disappeared when I installed it based on the instructions given by jetbrains.com.
cent os version 7.
it worked for me
ln -s /usr/lib64/libbz2.so.1.0.6 /usr/lib64/libbz2.so.1.0

pdf2image.exceptions.PDFPageCountError: Unable to get page count. error

Hello i am working on a project(converting pdf to jpeg images),i am using the pdf2img module in python for the same.But i am getting an error here:
images=convert_from_path(filename,poppler_path=r'C:\Program Files\Library\bin')
the error which i used to get in the beginning was poppler was not in path,but after correcting it now i am getting the error:
pdf2image.exceptions.PDFPageCountError: Unable to get page count.
Kindly help me to resolve this issue,
from pdf2image import*
the module i used is pdf2image
I had the same issue and solved it by installing Microsoft Visual C++ Redistributable which was missing from my computer (download here). You can check that the program pdfinfo.exe works fine, by running it from your console (the program is located in the Library/bin folder of poppler). If it fails, you will get the real error, otherwise it's caught and silenced by pdf2image.py telling you it could not get the page count.
Haw, I also encountered this problem.
This problem occurs if the script is executed on IDE, If you execute the script in the folder, There will be no problem.
Maybe it's the execution path.
from pdf2image import convert_from_path
images=convert_from_path("pdf_file_path_with_name",poppler_path="")
for i in range(len(images)):
images[i].save('image_name'+ str(i) +'.jpg', 'JPEG')
The reason could be if your PDF file path is not proper or broken. In my problem I solved this by changing quotes to single quote in file path. Maybe this is something related with encoding.
If you dive into pdf2image code, you'll see that this is happening after pdfinfo.exe is called on your pdf file. Try running it manually and you'll see what is happening there and if there any errors while running pdfinfo.exe.
I had this error: "The code execution cannot proceed because freetype.dll was not found...". So I just found freetype.dll in my Anaconda path (I used Anaconda to install pdf2image on Win10) and added this path to PATH environment variable, so it would be found. This was the only problem and I've got my images from pdf.
I encountered the same error but I correct my file path after that the issue will be resolved.

No such file or directory: 'gs' linux

I have a problem regarding using GhostScript to convert the ps file to JPG.
I have successfully got it to work in my Win7 machine, but for some reason it doesn't work in my Linux VM. I'm really not sure how to add the environment variables there(because that was needed in windows installation). Basically I'm testing it with the following code:
ps = cv.postscript(colormode='color')
img = Image.open(io.BytesIO(ps.encode('utf-8')))
img.save("wut.jpg")
But when executing it, I get the following error:
But when I type in "gs" in the command line in Linux, it says that it is installed:
Any kind of help would be highly appreciated. :)
In your shell, find the location of ghostscript with which gs.
Check that the path in python (os.environ['PATH']) contains the location of ghostscript.

pyinstaller and moviepy, ffmpeg works from terminal but not from finder

I am packaging python using pyinstaller 2.1 on OSX Mavericks. I have done this successfully in the past, but this is my first package that uses moviepy and ffmpeg. I use the following import:
from moviepy.video.io import ffmpeg_reader
Without this line in the code, everything works fine and I can launch my final package from its icon in finder. With the moviepy import, it will work if I launch from the terminal like this:
open ./myapp.app
but it will not open if I click on the icon from finder (opens quickly and crashes). I am assuming this has something to do with paths or environment variables that are set in terminal, but are not transferred to my packaged app. I have tried various hidden imports in pyinstaller for moviepy and its dependencies, but nothing seems to work. --debug mode hasn't provided much info to track it down. Any other ideas?
Thanks!
There are a few problems with moviepy and pyinstaller.
First, try writing the error to a text file
try:
from moviepy.video.io import ffmpeg_reader
except Exception as e:
with open('/absolute/path/to/error.txt',mode="w+") as f:
f.write(str(e))
1) You might need to modify these two files to remove the "exec" import statements
moviepy/audio/fx/all/__init__.py,
moviepy/video/fx/all/__init__.py
see here:
https://github.com/pratikone/videoVenom/blob/master/moviepy/audio/fx/all/__init__.py
https://github.com/pratikone/videoVenom/blob/master/moviepy/video/fx/all/__init__.py
2) You might need to have this statement imageio.plugins.ffmpeg.download(), so that ffmpeg is downloaded if not found.

Pydub (WindowsError: [Error 2] The system can not find the file specified)

I have a problem with Pydub module running in Windows and Linux. When I try open a mp3 file thus:
from pydub import AudioSegment
sound = AudioSegment.from_mp3("test.mp3")
Console show me the next message:
WindowsError: [Error 2] The system can not find the file specified
But...I have the file (test.mp3) in the same folder that the script, the name is correct.
Why I have this problem? (In Linux, have the same error)
Make sure that you have ffmpeg http://www.ffmpeg.org/ installed. You can get help from this official page.
Other thing that I can think of is that ffmpeg is installed and is in your path but not in the path of the process using pydub.
If this is the reason for the error, then you can set the absolute path to ffmpeg directly like shown below:
import pydub
pydub.AudioSegment.ffmpeg = "/absolute/path/to/ffmpeg"
sound = AudioSegment.from_mp3("test.mp3")
Give this a try.
The other way is put ffmpeg.exe,ffplay.exe in the current working directory
In jupyter notebook this error could persist since the error is with anaconda environment. You can solve this by installing ffmpeg from conda-forge
Got to anaconda prompt and type:
conda install -c conda-forge ffmpeg
In newer versions of pydub, you can specify the absolute path to your ffmpeg executable by setting the class attribute converter, e.g.:
from pydub import AudioSegment
AudioSegment.converter = "/usr/local/bin/ffmpeg"
In older versions the class attribute used to be ffmpeg, which is deprecated now.
Solution for MacOs and compiled Python
Maybe this solution is a bit hacky and not the best way, but it actually works for me on MacOs where I had the same problem.
It solves the problem if the python script cannot access the system $PATH variable. I had to do it this way because I run my python code as a compiled binary from a java program which means for some reasons that the system $PATH variable set on my MacOs system cannot be accessed by the compiled python code.
Add this to your python code:
import os
os.environ["PATH"] += os.pathsep + '/usr/local/bin'
'/usr/local/bin' is the default for MacOs - please change it if you installed ffmpeg in a different location.
I got the idea from an answer to that question: how do I modify the system path variable in python script?
you need to this:
1- Download and extract libav from Windows binaries provided here. (http://builds.libav.org/windows/)
2- Add the libav /bin folder to your PATH envvar
Install ffmpeg then add ffmpeg.exe to your environment path, it works fine after that.

Categories

Resources