python 国际象棋 - AttributeError : module 'chess' has no attribute 'pgn'

标签 python python-chess

我正在尝试将 python 国际象棋游戏导出到 pgn 文件。 documentation推荐 -

import chess
.
.
chessBoard = chess.Board()
.
.    
#Play the game and when over do below
game = chess.pgn.Game.from_board(chessBoard)
with open('output.pgn', 'a') as the_file:
    print(game, file=the_file, end="\n\n")

但是 chess.pgn.Game.from_board(chessBoard) 行抛出以下错误 -

AttributeError: module 'chess' has no attribute 'pgn'

当我键入 chess. 时,

pgn 也会出现在 intellisense 中,因此编辑器也能够看到 pgn 国际象棋。这是在 Windows 10 上的 VS2015 中运行的 python 3.x。

可能是什么原因造成的?

最佳答案

要使用 pgn 模块,您还必须执行 import chess.pgn

关于 python 国际象棋 - AttributeError : module 'chess' has no attribute 'pgn' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42641603/

相关文章:

python - 在没有 For 循环的 Python 中从 MySQL 中选择数组

python - 计算一组字符串(推文)的相似度

python - 通过列表中的索引获取元素比通过字典中的键获取元素更快

python - 如何获取 FEN 位置的字符串

python - 使用 Python 3 为 GNU Chess 编写 API/包装器

python - 当图形保存为 PDF 时,dpi 是否相关?

python - 求Python列表的平均值

python - 有没有办法将 python 棋盘转换为整数列表?

python - 在 pygame 中显示的缓冲区在 tkinter 中不显示