can't get Stockfish in Python to work, throws FileNotFoundError - python-3.x

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.

Related

Why pyexiv2 raises an error during runtime execution

I'm trying to use pyexiv2 to geotag photos from historical location data. However, my installation of pyexiv2 seems to be broken.
I'm running this script on a MacBook with MacOS Monterey. This was working perfectly on my previous MacBook so I believe it has something to do with the installation.
Here is the runtime error, it doesn't even pass import pyexiv2 at line 1 of the code.
stu#192 Development % python3 GPS-image.py /Users/stu/02.\ 2017-03-02\ 11.08.09.jpg -34.45223 132.342535
Traceback (most recent call last):
File "/Users/stu/Development/GPS-image.py", line 1, in <module>
import pyexiv2
File "/opt/homebrew/lib/python3.9/site-packages/pyexiv2/__init__.py", line 6, in <module>
from .core import *
File "/opt/homebrew/lib/python3.9/site-packages/pyexiv2/core.py", line 1, in <module>
from .lib import exiv2api
File "/opt/homebrew/lib/python3.9/site-packages/pyexiv2/lib/__init__.py", line 25, in <module>
ctypes.CDLL(os.path.join(lib_dir, 'libexiv2.dylib'))
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(/opt/homebrew/lib/python3.9/site-packages/pyexiv2/lib/libexiv2.dylib, 0x0006): tried: '/opt/homebrew/lib/python3.9/site-packages/pyexiv2/lib/libexiv2.dylib' (no such file), '/usr/local/lib/libexiv2.dylib' (no such file), '/usr/lib/libexiv2.dylib' (no such file)
Clearly files are missing, but why and how do I get them correctly installed?
Can someone tell me what the problem is and how to fix it?
Many thanks,
Stu

python subprocess SVN update FileNotFoundError

Below is a piece of python code that is causing an error. Can someone help with a solution who might have ran into this issue before?
>>> from subprocess import call
>>> call("svn update C:/folder1/subfoler1/ --non-interactive -q")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Python34\lib\subprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "D:\Python34\lib\subprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "D:\Python34\lib\subprocess.py", line 1112, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified```
I have gone through various other posts on similar issue but nothing related to svn update call. I haven't tried adding shell=True as this wasn't the best solution as suggested by many in this forum that it might be a security issue.
Found the solution: I did not have SVN command line tools installed on the system. The sub-process couldn't call the SVN commands.

Selenium using Python in 2019 on mac

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)

MoviePy Error: The system cannot find the file specified

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).

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