py-stockfish / stockfish

Integrates the Stockfish chess engine with Python (Official fork)
https://py-stockfish.github.io/stockfish/
MIT License
29 stars 8 forks source link

AttributeError: 'Stockfish' object has no attribute '_stockfish' #67

Closed API-Troubles closed 9 months ago

API-Troubles commented 9 months ago

Hi folks!

I'm quite new to this pypi package. I'm trying to run an instance of stockfish but have encountered this error (I ran this in replit.com).

Traceback (most recent call last):
  File "/home/runner/Chess-Analysis/main.py", line 3, in <module>
    stockfish = Stockfish()
  File "/home/runner/Chess-Analysis/.pythonlibs/lib/python3.10/site-packages/stockfish/models.py", line 47, in __init__
    self._stockfish = subprocess.Popen(
  File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/subprocess.py", line 1863, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'stockfish'
Exception ignored in: <function Stockfish.__del__ at 0x7f1dda0180d0>
Traceback (most recent call last):
  File "/home/runner/Chess-Analysis/.pythonlibs/lib/python3.10/site-packages/stockfish/models.py", line 757, in __del__
    if self._stockfish.poll() is None:
AttributeError: 'Stockfish' object has no attribute '_stockfish'

Here is the code I ran:

from stockfish import Stockfish

stockfish = Stockfish()

Any help is appreciated. Thanks in advance!

kieferro commented 9 months ago

This library is not a standalone, but only a wrapper. That means you need an executable Stockfish file, which you can download here or install on a Debian-based system with sudo apt install stockfish. And then you would need to specify the path to this file like in this example here.

I don't know how replit.com works exactly, but if you can't upload executables or install packages there, then it's possible that you just can't use this library.

API-Troubles commented 9 months ago

Ah got it!

Kind of confusing since the API Docs suggests that you can run the class without any file.

Anyway, do you mind pointing me towards the correct executable (If it matters replit.com runs off a version of linux)?

Thanks for the help so far!

kieferro commented 9 months ago

Kind of confusing since the API Docs suggests that you can run the class without any file.

Yes, that's right, that's because there's a default value, but I'll adjust that.

Anyway, do you mind pointing me towards the correct executable

I don't know exactly how replit.com works. So I don't know what the best method is for you. If you just need a downloadable version of Stockfish, look here: https://stockfishchess.org/download/

If you have access to a terminal and it's a Debian-based system, you can also try sudo apt install stockfish. But this is not going to be the latest version of Stockfish. If you need the latest version, you would have to compile from source.

API-Troubles commented 9 months ago

Sorry, forgot to close this issue.

I sucessfully ran the stockfish class now.

Thanks for your help!