1

所以基本上,我只想加载与脚本在同一个文件夹中的国际象棋引擎

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

这有什么问题?我以 root 用户身份运行脚本。

另外,如果我从 just 加载'engine',它会说文件不存在。

UPT:收到此错误

 _, 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'```
4

2 回答 2

1

如果我们检查文档,在播放部分中,您可以看到从根目录paths分配,如下所示:

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

虽然您要使用的引擎在您运行程序的同一文件夹中,但路径可以直接从安装Python的路径获取,我建议您_, engine = await chess.engine.popen_uci(r''+os.path.join(os.getcwd(), 'engine'))改用。

于 2022-02-27T22:51:51.050 回答
0

现在自己解决了这个问题。需要在引擎文件上执行这个

$ chmod 755 engine

所以基本上,它将文件权限更改为所需的权限。

于 2022-03-01T17:59:27.497 回答