我正在尝试使用 python-chess 库与 macOS 上的 Stockfish 交互,但在初始化过程中遇到超时错误。这是我的代码的简化版本:
import chess.engine
# Set your Stockfish path here
engine_path = '/Applications/Stockfish.app/Contents/MacOS/Stockfish'
if __name__ == '__main__':
engine = chess.engine.SimpleEngine.popen_uci(engine_path)
当我运行此脚本时,出现以下错误:
<UciProtocol (pid=20778)>: stderr >> 2024-08-10 11:19:05.137 Stockfish[20778:931410] WARNING: Secure coding is automatically enabled for restorable state! However, not on all supported macOS versions of this application. Opt-in to secure coding explicitly by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState:.
<UciProtocol (pid=20778)>: stderr >> 2024-08-10 11:19:05.139 Stockfish[20778:931410] Started app
/Users/username/.venv/lib/python3.9/site-packages/chess/engine.py:154: RuntimeWarning: A loop is being detached from a child watcher with pending handlers
warnings.warn("A loop is being detached from a child watcher with pending handlers", RuntimeWarning)
asyncio.exceptions.TimeoutError
我已尝试以下方法来解决该问题:
尽管做出了这些努力,错误仍然存在。 asyncio.exceptions.TimeoutError 表明脚本在等待 Stockfish 初始化时超时。
有人在 macOS 上遇到过类似的问题吗?我应该采取任何特定配置或额外步骤来解决此问题吗?
编辑:我正在使用Python chess库的1.10.0版本和Python的3.9版本。
我可以通过使用自制软件(
brew install stockfish
)安装stockfish而不是使用从应用商店安装的stockfish来让它工作。