0

我正在尝试通过 python chess 访问 Stockfish 评估,但是,每当我尝试运行代码时,都会遇到“[Errno 8] Exec 格式错误”。我尝试从文档中运行一些代码,但遇到了同样的错误。我读了一些文章,他们谈到在可执行代码中添加一个 shebang,但我没有看到其他人需要这样做,或者在文档中对它的任何引用。我真的很笨吗?对不起,我还是编码新手。文档代码如下:

import chess
import chess.engine

engine = chess.engine.SimpleEngine.popen_uci("/content/drive/MyDrive/stockfish_14.1_win_x64_avx2/stockfish_14.1_win_x64_avx2.exe")

board = chess.Board()
info = engine.analyse(board, chess.engine.Limit(time=0.1))
print("Score:", info["score"])
# Score: PovScore(Cp(+20), WHITE)

board = chess.Board("r1bqkbnr/p1pp1ppp/1pn5/4p3/2B1P3/5Q2/PPPP1PPP/RNB1K1NR w KQkq - 2 4")
info = engine.analyse(board, chess.engine.Limit(depth=20))
print("Score:", info["score"])
# Score: PovScore(Mate(+1), WHITE)

engine.quit()
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-9-9affa6765785> in <module>()
      2 import chess.engine
      3 
----> 4 engine = chess.engine.SimpleEngine.popen_uci("/content/drive/MyDrive/stockfish_14.1_win_x64_avx2/stockfish_14.1_win_x64_avx2.exe")
      5 
      6 board = chess.Board()

15 frames
/usr/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1549                         if errno_num == errno.ENOENT:
   1550                             err_msg += ': ' + repr(err_filename)
-> 1551                     raise child_exception_type(errno_num, err_msg, err_filename)
   1552                 raise child_exception_type(err_msg)
   1553 

OSError: [Errno 8] Exec format error: '/content/drive/MyDrive/stockfish_14.1_win_x64_avx2/stockfish_14.1_win_x64_avx2.exe'
4

1 回答 1

1

使用为 linux 编译的 stockfish,因为该机器不在 Windows 上运行。

如果遇到权限问题,请使用以下命令,例如:

chmod 777 "/content/drive.../stockfish_linux"
or
!chmod 777 "/content/drive.../stockfish_linux"
for google colab

stockfish_linux 是您的 stockfish 引擎文件。

于 2021-12-26T01:43:33.910 回答