You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python和Stockfish开发国际象棋机器人遇chess.uci属性错误求助

解决chess库中'uci'模块不存在的问题
  • 问题原因:chess库从1.0版本开始废弃了chess.uci模块,统一使用chess.engine模块处理与Stockfish等引擎的交互,直接调用chess.uci会触发AttributeError。

  • 修复步骤:

    1. 先确认你的chess库版本,执行命令:
      pip show chess
      
      若版本≥1.0,按以下方式修改代码。
    2. 将原代码:
      chess.uci.popen_engine("stockfish")
      
      替换为:
      import chess.engine
      engine = chess.engine.SimpleEngine.popen_uci("stockfish")
      
    3. 后续引擎交互需使用新API,比如获取最佳走法的示例:
      board = chess.Board()
      result = engine.play(board, chess.engine.Limit(time=0.1))
      board.push(result.move)
      print(board)
      engine.quit()
      
  • 注意事项:如果Stockfish可执行文件不在系统环境变量PATH中,需传入完整文件路径,例如Windows系统:"C:/Program Files/Stockfish/stockfish-windows-x86-64.exe",Linux/macOS系统:"/usr/local/bin/stockfish"。

内容的提问来源于stack exchange,提问作者ECMC

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 06:50:28