I don't know how to import chess.pgn on Python. I searched everywhere, but I didn't find anything. Can anybody here help me?

  • 5
    I guess you want chess.pgn from the python-chess library (?). The installation is covered in the documentation.
    – Ellie
    Commented Jan 16, 2020 at 19:57

2 Answers 2


If you've already installed python-chess via pip/conda/choco or your favourite package manager, then to use chess.pgn, in your .py files just call from chess import pgn or import chess.pgn. You have to explicitly write either import, even if you already have import chess.

Then you can use it like

from chess import pgn

with open("my_pgn_file.pgn", "r") as pf:
    game = pgn.read_game(pf)

If I had used import chess.pgn instead, then I call it by changing the last line to game = chess.pgn.read_game(pf).


First you need to install this library:

pip install python-chess

And make sure you're using the right pip, because still in some Linus distros pip and python are python 2.x and for python 3.x you should use pip3 and python3. If you want to check try this:

pip --version

You will see an output like this that will tell you what python you're using, in my case it's 3.8:

pip 19.2.3 from /usr/lib/python3.8/site-packages/pip (python 3.8)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.