Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to export a python-chess game to a pgn file. The documentation recommends -

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")

But the chess.pgn.Game.from_board(chessBoard) line throws the below error -

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

pgn shows up in intellisense as well when I type chess. so the editor is also able to see that there is a pgn in chess. This is python 3.x running in VS2015 on windows 10.

What could be causing it?

like image 994
Achilles Avatar asked Dec 24 '22 20:12

Achilles


1 Answers

To use the pgn module you'd also have to do import chess.pgn

like image 187
Mithilesh Gupta Avatar answered Feb 08 '23 23:02

Mithilesh Gupta