MoviePy Error: The system cannot find the file specified - python-3.x

I'm getting the error in the title when trying to run the example code below on Windows 10/Python 3.6.1/Sublime Text Editor 3. I made sure to set my MAGICK_HOME environment variable to point to where I manually installed ImageMagick. I made sure to only have 1 version of ImageMagick installed. I made sure FFMPEG, Numpy, imageio, Decorator, and tqdm were all installed.
Yes, the file "vidclip.mp4" exists. The desired behavior here is to simply clip the video and add text to the center as per the example on the github page, i.e. to simply run the code successfully.
Does anyone know what might be wrong?
Example code from github:
from moviepy.editor import *
video = VideoFileClip("vidclip.mp4").subclip(7,64)
# Make the text. Many more options are available.
txt_clip = ( TextClip("Ken Block who?",fontsize=70,color='white')
.set_position('center')
.set_duration(10) )
result = CompositeVideoClip([video, txt_clip]) # Overlay text on video
result.write_videofile("vidclip_edited.webm",fps=25) # Many options...
The full error trace:
Traceback (most recent call last):
File "C:\Users\av\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\VideoClip.py", line 1220, in __init__
subprocess_call(cmd, verbose=False )
File "C:\Users\av\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\tools.py", line 42, in subprocess_call
proc = sp.Popen(cmd, **popen_params)
File "C:\Users\av\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\av\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 990, 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 "C:\Users\av\Desktop\Desktop\Projects\Youtube\blender\test\testMoviePy.py", line 6, in <module>
txt_clip = ( TextClip("Ken Block who?",fontsize=70,color='white')
File "C:\Users\av\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\VideoClip.py", line 1229, in __init__
raise IOError(error)
OSError: MoviePy Error: creation of None failed because of the following error:
[WinError 2] The system cannot find the file specified.
.This error can be due to the fact that 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

Found the problem. I didn't realize it was imperative that I specify the location of ffmpeg.exe and convert.exe within ImageMagick's config_defaults.py file. After that, I install MoviePy (in that order).

Related

pdfkit [WinError 740] The requested operation requires elevation python3

I would like to convert an HTML page into a PDF file, based on the given URL. I have tried pdfkit, but it throws the following error:
[WinError 740] The requested operation requires elevation.
Code:
import pdfkit
path_wkthmltopdf = "D:\\w.exe"
config = pdfkit.configuration(wkhtmltopdf = path_wkthmltopdf )
pdfkit.from_url("http://www.google.com", 'd:\\out.pdf', configuration=config)
Output error:
n [42]: import pdfkit
path_wkthmltopdf = "D:\\w.exe"
config = pdfkit.configuration(wkhtmltopdf = path_wkthmltopdf )
pdfkit.from_url("http://www.google.com", 'd:\\out.pdf', configuration=config)
Traceback (most recent call last):
File "<ipython-input-42-58323936ac63>", line 5, in <module>
pdfkit.from_url("http://www.google.com", 'd:\\out.pdf', configuration=config)
File "C:\Users\31081\AppData\Local\conda\conda\envs\ml\lib\site-packages\pdfkit\api.py", line 26, in from_url
return r.to_pdf(output_path)
File "C:\Users\31081\AppData\Local\conda\conda\envs\ml\lib\site-packages\pdfkit\pdfkit.py", line 129, in to_pdf
stderr=subprocess.PIPE)
File "C:\Users\31081\AppData\Local\conda\conda\envs\ml\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 143, in __init__
super(SubprocessPopen, self).__init__(*args, **kwargs)
File "C:\Users\31081\AppData\Local\conda\conda\envs\ml\lib\subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "C:\Users\31081\AppData\Local\conda\conda\envs\ml\lib\subprocess.py", line 1017, in _execute_child
startupinfo)
OSError: [WinError 740] The requested operation requires elevation
I encountered with this problem too, I solved it by running .exe after run this it will create new dir, go inside this dir then bin dir you will find a exe file there like
C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe
So, replace "D:\w.exe" to above kind of path in your code then it will work
Cause
You are most likely getting that error as a result of downloading the Installer version, but not installig it. Thus, when running your code with wkhtmltopdf in the configuration pointing to that executable (which requires elevation of privilege), you get the following error:
OSError: [WinError 740] The requested operation requires elevation
Solution
You could install wkhtmltopdf by running that Installer version and choosing the destination folder (let's say C:\Program Files). You will find the wkhtmltopdf.exe file that you need to add to your configuration inside the bin folder. Hence, you should use as follows:
config = pdfkit.configuration(wkhtmltopdf=r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe')
pdfkit.from_url('http://google.com', 'out.pdf', configuration=config)
Another solution would be to download the 7z Archive version, extract the files, in which you'll find wkhtmltopdf.exe under the bin folder as well.
I ran into this issue when I had not gone through the full installation of the wkpdftohtml library. Once it was unpacked, this ran without need for elevation.

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

can't get Stockfish in Python to work, throws FileNotFoundError

I want to write a chess related program, where I need to evaluate moves. For this purpose, I have installed the python stockfish package from https://github.com/zhelyabuzhsky/stockfish.
But when I test even one line, with
from stockfish import Stockfish
stockfish = Stockfish()
I get the error
Traceback (most recent call last):
File "<ipython-input-12-fef147213e5f>", line 1, in <module>
stockfish = Stockfish()
File "C:\Users\ajdin\Anaconda3\lib\site-packages\stockfish.py", line 27, in __init__
stdout=subprocess.PIPE
File "C:\Users\ajdin\Anaconda3\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\ajdin\Anaconda3\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified.
I've also tried the same thing with a similar package from https://github.com/iamjarret/pystockfish with the pystockfish package, but the same error arose. (only now the main code was deep = Engine(depth=20) ).
I've searched online for this error, but couldn't really find a solution. Does anyone know what is wrong, am I missing any files here?
Any more required info, I am happy to give.
In both cases my pathfile "stockfish" was incorrect. It needed the full pathname as argument.

How to convert HTML to PDF with python3

How to convert HTML to PDF with python3? i write some code about webView with pyqt5,and i want to convert the html in the webView to pdf,what should i do?
i have tried to use the html2pdf,but it seem to only support python2.x
and i have tried to install the wkhtmltox-0.12.2.2_msvc2013-win64.exe and pdfkit,and then use the example code.
import pdfkit
pdfkit.from_url('http://google.com', 'out.pdf')
pdfkit.from_file('test.html', 'out.pdf')
pdfkit.from_string('Hello!', 'out.pdf')
but i also failed.and the error is following.
Traceback (most recent call last):
File "E:\Python34\lib\site-packages\pdfkit\configuration.py", line 21, in __init__
with open(self.wkhtmltopdf) as f:
FileNotFoundError: [Errno 2] No such file or directory: b''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
pdfkit.from_url('http://google.com', 'out.pdf')
File "E:\Python34\lib\site-packages\pdfkit\api.py", line 22, in from_url
configuration=configuration)
File "E:\Python34\lib\site-packages\pdfkit\pdfkit.py", line 38, in __init__
self.configuration = (Configuration() if configuration is None
File "E:\Python34\lib\site-packages\pdfkit\configuration.py", line 27, in __init__
'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
OSError: No wkhtmltopdf executable found: "b''"
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
but i also failed.so what should i do? My system is window7 x64 ,python's version is 3.4
Since this hasn't had an accepted answer yet, there is a great library that works in Python 3 that I found after much searching and failed attempts at using PyPDF2, wkhtmltopdf beta branch for Python 3, qpdf, etc. It is weasyprint. I have the related answer and sample code here.
For completeness sake, from the documentation:
from weasyprint import HTML
HTML('http://weasyprint.org/').write_pdf('/tmp/weasyprint-website.pdf')
and it really works that easy.
'set path' probably means add **.exe to the system environment variable $Path$. For example, add D:\Program Files\wkhtmltopdf\bin to $Path$.

Error while opening subprocess python

I get this error while trying to open a txt. file. Please tell how to fix it .
code: subprocess.Popen("/home/yash/Documents/ct.txt")
time.sleep(1)
error:
Traceback (most recent call last):
File "/home/yash/Documents/final_downloader22.py", line 5, in <module>
subprocess.Popen("/home/yash/Documents/ct.txt")
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
Text files are normally not executable. What do you mean with "open" here?
This could mean "open it so that I can use it in the program".
This works with file_object = open('/home/yash/Documents/ct.txt', 'r') and then using that file_object.
This as well could mean "let the file type's associated application open the file so that the user can edit it".
In this case, you would have to find out what the associated application is. How you do this is dependent on the OS you use as well as the window manager/desktop environment. It cannot be answered in a few short sentences.
You could use webbrowser module to open a text file for editing in a portable manner in a script:
import webbrowser
webbrowser.open("/home/yash/Documents/ct.txt")
From a command-line:
$ python -mwebbrowser "/home/yash/Documents/ct.txt"
See also patches for "Add shutil.open" Python issue.

Resources