FileNotFoundError:[Errno 2]尝试导入stockfish引擎时没有此类文件或目录

2024-05-20 20:25:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将Stockfish国际象棋引擎用于一个项目,并尝试导入该引擎(Stockfish.app)。我正在使用以下代码:

import subprocess

engine = subprocess.Popen("/Users/_/Downloads/stockfish.app", universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,)

但我得到了以下输出:

Traceback (most recent call last):
  File "/Users/_/Documents/Python/AI/Chess/Chess/stockfishAI.py", line 3, in <module>
    engine = subprocess.Popen("/Users/_/Downloads/stockfish.app", universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,)
  File "/opt/anaconda3/envs/tensor/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/opt/anaconda3/envs/tensor/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/_/Downloads/stockfish.app': '/Users/_/Downloads/stockfish.app'

我不知道为什么会发生这种情况,因为我已经准确地复制了目录。 这是目录中的文件

Contents

./Contents:
Info.plist  PkgInfo     _CodeSignature
MacOS       Resources   _MASReceipt

./Contents/MacOS:
Stockfish

./Contents/Resources:
AppIcon.icns            pawn_b.pdf
Assets.car          pawn_w.pdf
Base.lproj          queen_b.pdf
Binaries.entitlements       queen_w.pdf
bishop_b.pdf            rook_b.pdf
bishop_w.pdf            rook_w.pdf
en.lproj            stockfish-arm64
king_b.pdf          stockfish-x86-64
king_w.pdf          stockfish-x86-64-bmi2
knight_b.pdf            stockfish-x86-64-sse41-popcnt
knight_w.pdf            stockfish-x86-64-vnni256
nn-cb26f10b1fd9.nnue

./Contents/Resources/Base.lproj:
MainMenu.nib            SFMDocument.nib
Preferences.nib         SFMPreferenceCellView.nib

./Contents/Resources/en.lproj:
Credits.rtf     InfoPlist.strings

./Contents/_CodeSignature:
CodeResources

./Contents/_MASReceipt:
receipt

我不知道我在Mac上是否与此有关,从我看到的导入stockfish的示例来看,大多数都是在Windows上(导入.exe文件而不是.app) 如果可能的话,请帮助我,因为我对这个错误完全感到困惑


Tags: pyapppdfdownloadscontentsusersx86file