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.
Related
I am learning Python 3 using a Udemy course. One of the course modules asks us to install Pyperclip in order to try out simple code is the console.
import pyperclip
pyperclip.copy(‘Test’)
pyperclip.paste()
I believe this should output the word Test in the console.
I did the following:
Installed Stash
Installed Pyperclip by running the command ‘pip install Pyperclip’ from within Stash. Package installed fine
Went back to console and ran the import Pyperclip command. No errors
However, when I try to run the function Pyperclip.copy() or .paste() I get an error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/mobile/Containers/Shared/AppGroup/C6F5AC74-E13C-4A33-95BA-F075B9E680F9/Pythonista3/Documents/site-packages-3/pyperclip/__init__.py", line 120, in copy_osx_pbcopy
stdin=subprocess.PIPE, close_fds=True)
File "/var/containers/Bundle/Application/479FB713-67AD-4A41-9180-71A1C27C61E8/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/subprocess.py", line 708, in __init__
restore_signals, start_new_session)
File "/var/containers/Bundle/Application/479FB713-67AD-4A41-9180-71A1C27C61E8/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/subprocess.py", line 1261, in _execute_child
restore_signals, start_new_session, preexec_fn)
PermissionError: [Errno 1] Operation not permitted
I looked around for similar errors on stack overflow but the issues/ answers don’t seem to fit my situation. What am I doing wrong?
Pyperclip is not supported by Pythonista. Try their built in module, clipboard. http://omz-software.com/pythonista/docs/ios/clipboard.html
I'm a non-programmer trying to use Automate the Boring Stuff with Python to do exactly that. I watched all the videos and thought I was ready, but as I tried to get going I'm stuck on square zero.
I'm on a Mac OSx Mojave Version 10.14.2
Successfully installed Python 3.7.2
I'm trying to follow this chapter: http://automatetheboringstuff.com/chapter11/
Successfully installed Selenium because:
import selenium
does not give an error.
but when I run this:
from selenium import webdriver
browser = webdriver.Firefox()
I get this error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/Library/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: 'your\\path\\geckodriver.exe': 'your\\path\\geckodriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'your\path\geckodriver.exe' executable needs to be in PATH.
>>> driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/Library/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: 'your\\path\\geckodriver.exe': 'your\\path\\geckodriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'your\path\geckodriver.exe' executable needs to be in PATH.
I've tried everything in this: Selenium using Python - Geckodriver executable needs to be in PATH and I don't think it works anymore.
I've installed geckodriver and tried appending it to PATH but nothing seems to work. geckodriver is installed in /usr/local/bin/ and I've appended it to path by running export PATH=$PATH:/path/to/geckodriver and export PATH=$PATH:/usr/local/bin/geckodriver but I keep getting the same error
I've tried having both the newest Firefox and Firefox v46 installed because I read somewhere that it doesn't work after that version.
Any help is much appreciated.
I suggest to install with pip
pip install geckodriver-autoinstaller
and then add this code
import geckodriver_autoinstaller
# Check if the current version of geckodriver exists
# and if it doesn't exist, download it automatically,
# then add geckodriver to path
geckodriver_autoinstaller.install()
Set your executable_path
from selenium import webdriver
webdriver.Firefox(executable_path=r'path\to\geckdriver\geckodriver.exe')
executable_path –
Full path to override which geckodriver binary to use for Firefox 47.0.1 and greater, which defaults to picking up the binary from the system path.
from documentation
Edit: also works on lower versions firefox
Edit 2:
Perhaps you could verify the executable can be found by python itself.
import os.path
os.path.exists(file_path)
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
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.
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).