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
Related
I'm trying to install pyfluidsynth on windows. I used pip install pyfluidsynth in the command prompt, but when I tried to import fluidsynth in my python code I get:
ModuleNotFoundError: No module named 'FluidSynth'
When I tried to install FluidSynth (by using pip install fluidsynth) another binding package was installed with FluidSynth 0.2 from several years ago.
Can anybody help with specific details on how to install pyfluidsynth on windows and use it?
import FluidSynth
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'FluidSynth'
For recent FluidSynth versions there do not seem to be pre-built binaries for ms-windows available. (Note that development is now done on github; the sourceforge site is stale.) The latest source code releases are here.
But the FluidSynth wiki has instructions for building it on ms-windows.
Note: FluidSynth (more precisely, its shared library) is a requirement for using pyfluidsynth. See the README.
For me the following worked:
Go to the following link and download the pre-compiled (?) fluidsynth dll.
Add the directory of your fluidsynth dll to the path environment variable.
In the pyfluidsynth package. find the "fluidsynth.py" file, and edit the part where it's looking for the library "lib = find_library('fluidsynth')..." to search for the dll name, which was "libfluidsynth64" for the 64 bit version.
For whatever reason, (maybe version mismatch), the functions "fluid_synth_set_reverb_full" and "fluid_synth_set_chorus_full" are not supported, so comment those lines out from "fluidsynth.py".
And that's it. Save "fluidsynth.py" launch cmd, go into python, and import fluidsynth.
I haven't tested all the functionality of fluidsynth, but using pretty_midi, I was able to at least play midi through instrument soundfonts.
Hope this helps!
Installing fluidsynth on Windows
Download fluidsynth binaries from github: https://github.com/FluidSynth/fluidsynth/releases
Add extracted zip file’s bin to the path:
Eg: C:\Users*Your Username Here**** YOUR path to extracted zip ***\fluidsynth-2.1.6-win10-x64\bin
Download fluidsynth python library: the repository for python fluidsynth is:
https://github.com/nwhitehead/pyfluidsynth.
https://github.com/nwhitehead/pyfluidsynth/archive/master.zip
Once extracted, it must be installed:
python setup.py install
The extracted master.zip has fluidsynth.py This python file is the file to “import” into the python code. In the test folder it has example.sf2 which is used in an installation test: paths to these two files need to be set to your own locations.
import time
import fluidsynth
fs = fluidsynth.Synth()
fs.start()
sfid = fs.sfload("example.sf2")
fs.program_select(0, sfid, 0, 0)
fs.noteon(0, 60, 30)
fs.noteon(0, 67, 30)
fs.noteon(0, 76, 30)
time.sleep(1.0)
fs.noteoff(0, 60)
fs.noteoff(0, 67)
fs.noteoff(0, 76)
time.sleep(1.0)
fs.delete()
The above python code sample plays a single note. Getting this to work confirms everything is working.
For me, next works:
Call pip install --upgrade pyfluidsynth
Download precompiled DLL from: https://zdoom.org/downloads#Support
If you use 64x version rename file from libfluidsynth64.dll to libfluidsynth.dll
Place it into C:\Windows\System32
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()
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 having some trouble running a python script on my Windows 7 platform. I've installed Python and also cairo, last one using "pip". I'm running the script using this command:
C:\Python34>python.exe label/make_label.py
and I get the following error message:
Traceback (most recent call last):
File "label/make_label.py", line 6, in <module>
import cairocffi as cairo
File "C:\Python34\lib\site-packages\cairocffi\__init__.py", line 41, in <modul
e>
cairo = dlopen(ffi, *CAIRO_NAMES)
File "C:\Python34\lib\site-packages\cairocffi\__init__.py", line 34, in dlopen
return ffi.dlopen(names[0]) # pragma: no cover
File "C:\Python34\lib\site-packages\cffi\api.py", line 118, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Python34\lib\site-packages\cffi\api.py", line 411, in _make_ffi_libra
ry
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Python34\lib\site-packages\cffi\api.py", line 400, in _load_backend_l
ib
return backend.load_library(name, flags)
OSError: cannot load library libcairo.so.2: error 0x7e
What I've already done is the following:
Added the PATH to GTK/bin in the environmental variable
I check the folder GTK/bin and found "libcairo-2.dll" so I renamed it to libcairo.so
I don't know what other information could be useful in solving this but please let me know and I'll try to add it.
On Mac OS X using homebrew:
brew install cairo
brew install pango
It seems cairo depends a shared library which is not in standard search library, however, the python is calling dlopen to dynamic load the library, so you could try to put the libcairo.so.2(if it's a link, then make sure the reference locates at the same folder) in the working directory. You can also try pkg-config to set the environment. see here http://people.freedesktop.org/~dbn/pkg-config-guide.html
I just had the same issue ("OSError: cannot load library libcairo.so.2: error 0x7e"), and this is how I solved the problem on Windows (Windows 7 x64, Python 3.4.2 x86 (MSC v.1600 32 bit)):
downloaded an all-in-one bundle of the GTK+ stack including 3rd-party dependencies (which contains libcairo-2.dll and other Cairo-related libraries)
extracted this archive to a path which does NOT contain spaces (e.g. C:\Programs\gtk+)
added the extracted directory's bin subdirectory (which contains the mentioned libcairo-2.dll and other necessary files) to the PATH
Win+R, SystemPropertiesAdvanced
Environment Variables...
added this directory to the Path variable (either to the user variables or system variables, after a semicolon) (e.g. ...;C:\foo;C:\Programs\gtk+)
OK
pip install cairosvg
tested it with a very simple code, which already had worked:
import cairosvg
testsvg = '<svg height="30" width="30">\
<text y="10">123</text>\
</svg>'
svgConvertedToPng = cairosvg.svg2png(bytestring=testsvg)
print(svgConvertedToPng)
Solved on Windows 10 as follows:
download the headless UniConverter installer
Find where it installed and add its dll subdirectory to the system path.
Close and re-open the command window to get the updated path.
I just fixed this on Mac OSX 10.13 with an Anaconda Python installation and cairosvg:
$ conda install cairo pango gdk-pixbuf libffi cairosvg
$ cairosvg image.svg -o image.png
I got the idea from https://cairosvg.org/documentation/, which says that all its dependencies can be installed with WeasyPrint. WeasyPrint's documentation for installation on MacOSX at https://weasyprint.readthedocs.io/en/latest/install.html#macos says to get the dependencies from HomeBrew:
brew install python3 cairo pango gdk-pixbuf libffi
So I tried it with conda instead and it worked fine.
I tried installing pdfkit Python API in my windows 8 machine. I'm getting issues related to path.
Traceback (most recent call last):
File "C:\Python27\pdfcre", line 13, in <module>
pdfkit.from_url('http://google.com', 'out.pdf')
File "C:\Python27\lib\site-packages\pdfkit\api.py", line 22, in from_url
configuration=configuration)
File "C:\Python27\lib\site-packages\pdfkit\pdfkit.py", line 38, in __init__
self.configuration = (Configuration() if configuration is None
File "C:\Python27\lib\site-packages\pdfkit\configuration.py", line 27, in __init__
'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
IOError: No wkhtmltopdf executable found: ""
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf
Is anybody installed Python PDFKIt in windows machine? How to resolve this error.
My sample code :
import pdfkit
import os
config = pdfkit.configuration(wkhtmltopdf='C:\\Python27\\wkhtmltopdf\bin\\wkhtmltopdf.exe')
pdfkit.from_url('http://google.com', 'out.pdf')
The following should work without needing to modify the windows environment variables:
import pdfkit
path_wkhtmltopdf = r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
pdfkit.from_url("http://google.com", "out.pdf", configuration=config)
Assuming the path is correct of course (e.g. in my case it is r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe').
Please install wkhtmltopdf using,
sudo apt install -y wkhtmltopdf
for windows machine install it from below link, http://wkhtmltopdf.org/downloads.html
and you need to add wkhtmltopdf path into environment variables
IOError: 'No wkhtmltopdf executable found'
Make sure that you have wkhtmltopdf in your $PATH or set via custom configuration. where wkhtmltopdf in Windows or which wkhtmltopdf on Linux should return actual path to binary.
Adding this configuration line worked for me:
config = pdfkit.configuration(wkhtmltopdf="C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe")
pdfkit.from_string(html, 'MyPDF.pdf', configuration=config)
From github
Seems you need to pass configuration=config as argument.
I am learning python today, and I met the same problem, lately I set the windows enviroment variables and everything is OK.
I add the install path of wkhtml to the path, for example:"D:\developAssistTools\wkhtmltopdf\bin;" is my install path of wkhtml, and I add it to the path, everything is OK.
import pdfkit
pdfkit.from_url("http://google.com", "out.pdf")
finally, I find a out.pdf.
import pdfkit
path_wkthmltopdf = b'C:\Program Files\wkhtmltopdf\\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
pdfkit.from_url("http://google.com", "rajul-url.pdf", configuration=config)
pdfkit.from_file("output.xml","rajul-pdf.pdf", configuration=config)
The Above Code block is working perfectly fine for me. Please note that file which needs to be converted is in the same directory where the pdf file is creating.
Ran into the same problem on a Mac. For some reason-- it worked after unistalling the pip installation and reinstall wkhtmltopdf using brew
pip uninstall wthtmltopdf
and use brew
brew install Caskroom/cask/wkhtmltopdf
You need set:
pdfkit.from_url('http://google.com', 'out.pdf',configuration=config)
Found the decode on a windows platform needed to be a binary string, try:
path_wkthmltopdf = b'C:\Program Files\wkhtmltopdf\\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
pdfkit.from_url(url=urlpath, output_path=pdffilepath,configuration=config)
def urltopdf(url,pdffile):
import pdfkit
'''
input
- url : target url
- pdffile : target pdf file name
'''
path_wkthmltopdf = 'D:\\Program Files (x86)\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
#pdfkit.from_url(url=urlpath, output_path=pdffilepath,configuration=config)
pdfkit.from_url(url,pdffile,configuration=config)
urltopdf('http://www.google.com','pdf/google.pdf')
very good solution!
thanks everyone!
When I tried all of the above methods, I was till facing Permission Error as I don't have the admin rights to my workstation.
If that's the case for you too, then make sure when you install your wkhtmltopdf.exe. The destination folder for installation is in your python site-packages folder, or add the directory to sys.path.
Normally it gets installed in Program files folder.
I changed the installation directory and this works for me:
import pdfkit
pdfkit.from_url("http://google.com", "out.pdf")
[For Ubuntu/Debian]
first run: sudo apt-get update --fix-missing
then: sudo apt-get install -y wkhtmltopdf
hope it would solve your problem.
for windows Try to use the complete path C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe
No need to write wkhtmltopdf path into code. Just define an environment variable for that, and it works.
import pdfkit
pdfkit.from_url('http://google.com', 'out.pdf')
For me this code is working.