2

I know this isn't a programming forum, though it's chess-related, hence the placement on here. Basically, I'm trying to setup stockfish with Python on my PC. I installed it via pip install stockfish.

So I went on and tried to setup the Stockfish via:

from stockfish import Stockfish

stockfish = Stockfish(r'C:\Users\Acer\Desktop\chess\stockfish-11-win')

That throws a WinError 5, access denied:

Exception ignored in: <function Stockfish.__del__ at 0x0429AA48>
Traceback (most recent call last):
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\stockfish\models.py", line 270, in __del__
    self.stockfish.kill()
AttributeError: 'Stockfish' object has no attribute 'stockfish'
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    emily = Stockfish(r'C:\Users\Acer\Desktop\chess\stockfish-11-win\src')
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\stockfish\models.py", line 33, in __init__
    self.stockfish = subprocess.Popen(
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Zugriff verweigert

I tried different Stockfish Downloads, running the Idle or CMD as admin, re-installed and used different PCs, but I somehow don't get to work with Stockfish - anyone able to help me out bypassing the access denied? What do I miss when initializing?

  • I'm not sure about this, but I think you need to have the Stockfish engine already installed and r'C:\Users\Acer\Desktop\chess\stockfish-11-win' is the path to the binary. pip install stockfish just allows you to easily call the engine from your Python code. – Pranav Hosangadi Aug 28 at 16:18
  • Yeah right, I installed the 11th version for Windows and have it in the directory you mentioned. (Just the unzipped downloaded file), did I miss something? – velotoy Aug 28 at 16:35
4

The argument needs to point to the Stockfish executable. If you download the v11 zip from the Stockfish website, extract it and find the directories with the executables.

I extracted it to C:\Users\<username>\Downloads\stockfish-11-win

The executables are in C:\Users\<username>\Downloads\stockfish-11-win\Windows

Stockfish executables

To use the executable, give the path to the executable like so:

from stockfish import Stockfish

stockfish = Stockfish(r'C:\Users\<username>\Downloads\stockfish-11-win\Windows\stockfish_20011801_x64.exe')

The default value for the path you give is "stockfish", so if you add your directory with the executables to the path, and rename the exe you want to stockfish, you should be able to do:

from stockfish import Stockfish

stockfish = Stockfish()

Re. your comment:

no other stockfish related "commands" will work: OSError: [Errno 22] Invalid argument ... so it seemingly fixed a problem but the next instantly occured.

The ArgumentError is presumably because you're passing a wrong argument. For example, I ran the commands in the readme in the github repository and it works perfectly fine.

Demo

| improve this answer | |
  • First off, thanks for the help! I tried your suggested solution and at least it doesn't throw up the earlier error, though it opens the .exe file (upon executing the .py file) and no other stockfish related "commands" will work: OSError: [Errno 22] Invalid argument ... so it seemingly fixed a problem but the next instantly occured. @Pranav Hosangadi – velotoy Aug 28 at 18:08
  • @velotoy, see if my edit helps. Make sure the arguments you pass are in the format it expects. – Pranav Hosangadi Aug 28 at 18:16
  • I ran it the script (initializing the stockfish directory) and an external .cmd popup appeared. Upon closing it (as mentioned) no arguments, e.g. set_position, .get_board_visual, etc. worked. – velotoy Aug 28 at 18:17
  • I think the external cmd popup is the underlying stockfish process (although I don't see why it would open it as a popup instead of a subprocess). It should work if you don't close it. I don't see any external popup on my computer when running in either a command prompt or in Spyder. – Pranav Hosangadi Aug 28 at 18:35
  • Okay thanks! Yeah, I'm running it in the standard idle, but I suppose it's fine. Marked as working! – velotoy Aug 28 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.