Home > Mobile >  How can I resolve import errors?
How can I resolve import errors?

Time:09-14

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)

CodePudding user response:

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

CodePudding user response:

If you have pip installed, you can type this in a terminal sudo pip install easyAI. Otherwise, download the source code (for instance on Github), unzip everything into one folder and in this folder, in a terminal, type sudo python setup.py install. Then you can try

from easyAI import TwoPlayerGame, Human_Player, AI_Player, Negamax

  • Related