Search code examples
pythonpython-3.xpython-2.7importimporterror

How can I resolve import errors?


pip install easyAI

from easyAI import TwoPlayersGame, id_solve, Human_Player, AI_Player
from easyAI.AI import TT

ImportError: cannot import name 'TwoPlayersGame' from 'easyAI' (/usr/local/lib/python3.7/dist-packages/easyAI/__init__.py)


Solution

  • In fact, it's just a typo, you should use TwoPlayerGame to replace TwoPlayersGame.

    Usually, you could use dir to get what parameters is in a object like next:

    Python 3.7.12 (default, Sep 28 2021, 19:43:27)
    [GCC 10.2.1 20210110] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import easyAI
    >>> dir(easyAI)
    ['AI', 'AI_Player', 'DUAL', 'DictTranspositionTable', 'HashTranspositionTable', 'Human_Player', 'Negamax', 'NonRecursiveNegamax', 'Player', 'SSS', 'TranspositionTable', 'TwoPlayerGame', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'mtd', 'solve_with_depth_first_search', 'solve_with_iterative_deepening']
    >>> from easyAI import TwoPlayerGame