1

So basically, I just want to load chess engine which is in the same folder with script

_, engine = await chess.engine.popen_uci('./engine')

What is wrong with this? I am running the script as a root user.

Also, if I load from just 'engine', it says file doesn't exist.

UPT: getting this error

 _, self.engine = await chess.engine.popen_uci(r'' + os.path.join(os.getcwd(), 'engine'))
  File "/usr/local/lib/python3.8/dist-packages/chess/engine.py", line 2642, in popen_uci
    transport, protocol = await UciProtocol.popen(command, setpgrp=setpgrp, **popen_args)
  File "/usr/local/lib/python3.8/dist-packages/chess/engine.py", line 1214, in popen
    return await asyncio.get_running_loop().subprocess_exec(cls, *command, **popen_args)  # type: ignore
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1630, in subprocess_exec
    transport = await self._make_subprocess_transport(
  File "/usr/lib/python3.8/asyncio/unix_events.py", line 197, in _make_subprocess_transport
    transp = _UnixSubprocessTransport(self, protocol, args, shell,
  File "/usr/lib/python3.8/asyncio/base_subprocess.py", line 36, in __init__
    self._start(args=args, shell=shell, stdin=stdin, stdout=stdout,
  File "/usr/lib/python3.8/asyncio/unix_events.py", line 789, in _start
    self._proc = subprocess.Popen(
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/root/ChessBot/engine'```
Exenifix
  • 71
  • 1
  • 7

2 Answers2

1

If we check documentation, in the playing section, you can see that the paths are assigned from the root like this:

r"C:\Users\xxxxx\Downloads\stockfish_14_win_x64\stockfish_14_win_x64_avx2.exe"
or "/usr/bin/stockfish".

Although the engine you want to use is in the same folder where you run the program, the path may be obtained directly from the path where Python is installed, I would recommend using _, engine = await chess.engine.popen_uci(r''+os.path.join(os.getcwd(), 'engine')) instead.

user11717481
  • 1
  • 9
  • 15
  • 25
  • This doesn't seem like an issue of path, more like issue of OS. In windows, it worked totally fine with relative path. And here on DigitalOcean's droplet with Ubuntu 20.04 it regularly gives me something like "permission denied", not only in python. However, thanks for your answer, I will try it. – Exenifix Feb 28 '22 at 04:52
  • Still getting that error, didn't help – Exenifix Mar 01 '22 at 17:43
  • the use of `os.getcwd()` together with the name of your *chess engine* could solve problems with the path of the files, although this raises the question why not use it as an engine (I think it is one of the most common and widely used in applications) `"stockfish"` – user11717481 Mar 02 '22 at 11:39
0

Resolved this by myself now. Need to execute this on engine file

$ chmod 755 engine

So basically, it changes files permissions to the required ones.

Exenifix
  • 71
  • 1
  • 7