python-chess - AttributeError:模块'chess'没有属性'pgn'

Ach*_*les 3 python python-chess

我正在尝试将python-chess游戏导出到pgn文件.该文件建议-

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")
Run Code Online (Sandbox Code Playgroud)

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

AttributeError:模块'chess'没有属性'pgn'

pgn当我输入时,也会出现在intellisense中,chess.因此编辑器也可以看到有一个pgnin chess.这是在Windows 10上的VS2015中运行的python 3.x.

可能是什么原因造成的?

Mit*_*pta 7

要使用该pgn模块,您还必须这样做import chess.pgn