Python-chess open UCI engine permission error denied - python

I am currently creating a python script that opens a chess engine, Stockfish, using python-chess, and chess.uci. However, when I try opening up the stockfish engine, I get
PermissionError: [Errno 13] Permission denied
So I looked more into this issue, and apparently, you cannot open directories or folders directly. However, looking into the documentation for opening a UCI engine for python-chess, the example shows opening what seems to be a directory under /usr/bin
The documentation is here: https://python-chess.readthedocs.io/en/v0.23.10/uci.html
Is there any other way to open an engine using UCI?
My OS system is Mac OS.

Ok, sorry, I'm late ^^
I've got the same problem few month ago.
First, on Mac, be sure your file is not a .exe file. It should be a Mac executable (i.e. if you double click on your file, it will open the Terminal).
If not, install Homebrew, and $ brew install stockfish.
Next find the Stockfish executable path in your Finder and open a new Terminal window for its folder emplacement. Paste $ chmod +x your_stockfish_exe_name and retry to open Stockfish with Python.

Related

OS permissions causing issue with removing files in Pycharm

On my company laptop (running Windows 10) I am using PyCharm to develop some scripts where I use the os module to create and delete directories. However, whenever I call a function that deletes old copies of files, I get a permission error:
PermissionError: [WinError 5] Access is denied: 'C:\\\\Users\\\\User\\\\PycharmProjects\\\\Project
I've narrowed down the issue to the fact that my company has set permissions that do not allow for anyone else to delete subfolders and files:
I am unable to edit this permission. I am able to add new permissions.
I've tried running PyCharm as an administrator to see if that would allow the python script running in PyCharm to bypass the above settings and delete files, but that seems to have failed.
Is there any way for me to get a python script running in PyCharm to bypass these permissions? I believe if I were to download my entire project and execute the script in Powershell or CMD (being run as admin) that I would be able to do what I want to do, but I'm currently working in a venv and would rather not have to load all of my package dependencies onto my machine.
My current workaround, while crude, is to change the filepath for each of the files to be the recycling bin. Then when running my script, new files will simply fill the now empty folders. To do this I imported the send2trash module.
pip install send2trash
from send2trash import send2trash
send2trash('C:\\path\\to\\your\\file')
I haven't tested any commands to empty the recycling bin programatically (I'd be wary to delete the contents there in case something important was placed there by mistake), but for now this somewhat handles what I need. Ideally I would like to be able to delete the specific files.

WSL2: Python rename files from with VS Code debugger

I'm using WSL2 with a Ubuntu distro with a conda package manager. I can read and edit files on Windows ( accessed via /mnt/c) using the Visual Studio Code GUI (launched by code . in the WSL Ubuntu terminal).
I have following script where I'm trying to remove spaces from the name of all pdf files:
import os
fldr = '/mnt/c/Documents and Settings/Lenovo/Desktop/'
for f in os.listdir(fldr):
if 'pdf' in f:
print(f)
os.rename(fldr+f, fldr+f.replace(' ','_'))
print(f.replace(' ','_'))
If I run the script via the debugger (F5) I get a permission error [Errno 13]
If I use the terminal created by debugger to manually rename using Python code, I don't get the permission error.
I am pretty sure there is a difference between the user that runs the debugger (which runs in your windows) and the user that is running inside WSL.
try running the following command to set the username the same as the windows one:
wsl --user <your username>

How to run files in the working directory through Git Bash and Python

I'm having some issues running Python 3, which I installed with Anaconda, through Git Bash. I'm able to access the interactive environment by entering python but whenever I enter:
python webscraper.py
I get this:
C:/Users/[My username]/anaconda3/python.exe: can't open file 'webscraper.py': [Errno 2]
No such file or directory
The Python file is in the same directory I'm currently working in when I'm getting these errors. The path to my version of Python through Anaconda also looks like it's correct. I was previously able to test scripts in Bash but had to reinstall it to solve some other issue.
First, check if you are using the right python:
which python # in your git bash session
Then test it with the full absolute pathname of the file, as described here:
python /full/path/to/webscrapper.py

How to set up PyInstaller in PyCharm for a project using External Tools inside venv?

I have a project in PyCharm with multiple Python files, as well as some text files, which I want to export into .exe via PyInstaller (I'm on Win 7). The project uses some external modules installed inside venv via pip (PyInstaller is one of them).
I want to keep things simple and not use any modules outside venv in the build, for obvious reasons. However, when I try to execute the PyInstaller tool on the project folder, I get a permission error: PermissionError: [Errno 13] Permission denied. Using PyInstaller on the main.py inside the project builds it just fine at first glance, but running the .exe in cmd shows an error loading Python DLL. How do I do it right? Something tells me the spec should be created beforehand to include all files and modules used in the project.
To answer the question in the title, the Arguments you specify in PyCharm are passed to pyinstaller.exe when you execute the tool. So it should be the path to main.py or the path to your .spec file, not $FilePath$ which is a macro that gets replaced by the file that is currently open in PyCharm.
You should definitely have a .spec file, that is committed to version control. This makes your PyInstaller builds more consistent, and allows others to reproduce them easily. See https://pyinstaller.readthedocs.io/en/stable/spec-files.html

PyCharm error: [Errno 13] Permission denied

I am using PyCharm for executing my Python programs. Today, I had tried updating all the packages using Project Interpreter. I received the following error in the process:
error: [Errno 13] Permission denied
After which none of my Python libraries are shown in Project Interpreter list.
I am using PyCharm Community Edition 2016.2.3 in Mac OS X 10.11.6.
It looks like you need to give your interpretter root permissions. There is a tutorial here on how to do this
Try to remove the shebang if you have it in your code and then try to run it......BTW this Worked for me.
The PermissionError: [errno 13] permission denied error occurs when you try to access a file from Python without having the necessary permissions. In your case the file (or directory ???) of interest is /var/folders/2k/_1tccbln53165lgvzvzt3b480000gp/T/tmprqbtrpspycharm-management/setuptools-18.1. You might want to use chmod or chown to change access permissions to it.
sudo visudo -f /etc/sudoers.d/python
inside the /etc/sudoers.d/python you just created enter these details in the given format <current_username> <hostname> = (root) NOPASSWD: <full path to python> ie mostly you might have creating a virtual env in pycharm when you start a project. so in that you would find a bin folder. inside which you will find many python virtual interpreters(mention that absolute path ex /home/<project_foldername>/bin/python).
anywhere you can create shell script python-sudo.sh
inside python-sudo.sh mention like this #!/bin/bash sudo <same_path_you_given_in_"/etc/sudoers.d/python"_file> "$#"
Now open your pycharm and project you need to run/debugg the go to setting > project:projectname > Python Interpreter Click on Wheel Icon and Then click on "Add"
In the new window that popup select Existing Environment > Select the shell script which you created python-sudo.sh. Then click OK > and then Click Apply
Make sure that on top right side of editor near to green run button Run/Debug configuration small drop down menu for your file which you are about to execute/debug click on Edit Configuration and the same python interpreter is selected there as well which is python-sudo.sh.
Now try executing/debugging, it should work.
I had the same issue after changing python directory. Then I changed the interpreter setting to a new python directory then 'Run' the code from the Menu and selected 2nd 'Run' option or you can just use the shortcut as Alt+Shift+F10' and a small window appears with your code file name then select the filename which you cant to Run.
This resolved my issue!
enter image description here
I encountered the same problem. When I removed the python libs installed out of Pycharm IDE, I found that there is no installation problem. Please use the pip uninstall command.

Categories