lichess-bot-devs / lichess-bot

A bridge between Lichess bots and chess engines
GNU Affero General Public License v3.0
764 stars 448 forks source link

Error when trying to start match: AttributeError: module 'chess.engine' has no attribute 'Opponent' #875

Closed kurt1288 closed 11 months ago

kurt1288 commented 11 months ago

Running on Windows. I've run the installation steps without any errors. The lichess-bot itself starts and doesn't show any errors upon startup. It searches for matchmaking just fine. It's when it tries to actually start the game, it runs into a problem.

Full debug output:

Event: {'type': 'challenge', 'challenge': {'id': 'fI8ENsiD', 'url':     lichess-bot.py:373
                             'https://lichess.org/fI8ENsiD', 'status': 'created', 'challenger':
                             {'id': 'puffinbot', 'name': 'PuffinBot', 'rating': 2000, 'title':
                             'BOT', 'provisional': True, 'online': True, 'lag': 4}, 'destUser':
                             {'id': 'honzovy-sachy-2', 'name': 'honzovy-sachy-2', 'rating': 2165,
                             'title': 'BOT', 'online': True}, 'variant': {'key': 'standard', 'name':
                             'Standard', 'short': 'Std'}, 'rated': True, 'speed': 'rapid',
                             'timeControl': {'type': 'clock', 'limit': 900, 'increment': 5, 'show':
                             '15+5'}, 'color': 'random', 'finalColor': 'black', 'perf': {'icon':
                             '\ue017', 'name': 'Rapid'}}, 'compat': {'bot': True, 'board': True}}
[11/27/23 19:58:19] DEBUG    Event: {'type': 'gameStart', 'game': {'fullId': 'fI8ENsiDX785',         lichess-bot.py:373
                             'gameId': 'fI8ENsiD', 'fen':
                             'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1', 'color':
                             'black', 'lastMove': '', 'source': 'friend', 'status': {'id': 20,
                             'name': 'started'}, 'variant': {'key': 'standard', 'name': 'Standard'},
                             'speed': 'rapid', 'perf': 'rapid', 'rated': True, 'hasMoved': False,
                             'opponent': {'id': 'honzovy-sachy-2', 'username': 'BOT
                             honzovy-sachy-2', 'rating': 2165}, 'isMyTurn': False, 'secondsLeft':
                             900, 'compat': {'bot': True, 'board': True}, 'id': 'fI8ENsiD'}}
                    INFO     --- Process Used. Count: 1. IDs: {'fI8ENsiD'}                           lichess-bot.py:257
                    DEBUG    Starting new HTTPS connection (1): lichess.org:443                   connectionpool.py:971
[11/27/23 19:58:20] DEBUG    https://lichess.org:443 "GET /api/bot/game/stream/fI8ENsiD HTTP/1.1" connectionpool.py:452
                             200 None
                    DEBUG    Initial state: {'id': 'fI8ENsiD', 'variant': {'key': 'standard',        lichess-bot.py:575
                             'name': 'Standard', 'short': 'Std'}, 'speed': 'rapid', 'perf': {'name':
                             'Rapid'}, 'rated': True, 'createdAt': 1701143900218, 'white': {'id':
                             'honzovy-sachy-2', 'name': 'honzovy-sachy-2', 'title': 'BOT', 'rating':
                             2165}, 'black': {'id': 'puffinbot', 'name': 'PuffinBot', 'title':
                             'BOT', 'rating': 2000, 'provisional': True}, 'initialFen': 'startpos',
                             'clock': {'initial': 900000, 'increment': 5000}, 'type': 'gameFull',
                             'state': {'type': 'gameState', 'moves': '', 'wtime': 900000, 'btime':
                             900000, 'winc': 5000, 'binc': 5000, 'status': 'started'}}
                    DEBUG    Starting engine: ['E:\\Documents\\LichessBot\\engines\\Puffin.exe']   engine_wrapper.py:67
                    DEBUG    Using proactor: IocpProactor                                        proactor_events.py:625
                    DEBUG    <UciProtocol (pid=15104)>: Connection made                                   engine.py:987
                    DEBUG    <UciProtocol (pid=15104)>: << uci                                           engine.py:1009
                    DEBUG    <UciProtocol (pid=15104)>: >> Puffin 0.1                                    engine.py:1035
                    DEBUG    <UciProtocol (pid=15104)>: >> id name Puffin 0.1                            engine.py:1035
                    DEBUG    <UciProtocol (pid=15104)>: >> id author Kurt Peters                         engine.py:1035
                    DEBUG    <UciProtocol (pid=15104)>: >> option name Hash type spin default 32 min 1   engine.py:1035
                             max 512
                    DEBUG    <UciProtocol (pid=15104)>: >> option name Threads type spin default 1 min 1 engine.py:1035
                             max 256
                    DEBUG    <UciProtocol (pid=15104)>: >> uciok                                         engine.py:1035
                    DEBUG    <UciProtocol (pid=15104)>: << setoption name Hash value 256                 engine.py:1009
                    DEBUG    <UciProtocol (pid=15104)>: << isready                                       engine.py:1009
                    DEBUG    <UciProtocol (pid=15104)>: >> readyok                                       engine.py:1035
                    DEBUG    <UciProtocol (pid=15104)>: << quit                                          engine.py:1009
                    DEBUG    <UciProtocol (pid=15104)>: Process exited                                   engine.py:1006
                    DEBUG    <UciProtocol (pid=15104)>: Connection lost (exit code: 100, error: None)     engine.py:993
                    INFO     Backing off play_game(...) for 1.0s (AttributeError: module 'chess.engine'  _common.py:105
                             has no attribute 'Opponent')
                    DEBUG    Backing off 1.0 seconds after 1 tries calling function <function play_game   lichess.py:63
                             at 0x0000017AC4883010> with args () and kwargs {'li': <lichess.Lichess
                             object at 0x0000017AC0CA09D0>, 'control_queue': <AutoProxy[Queue] object,
                             typeid 'Queue' at 0x17ac486bf10>, 'user_profile': {'id': 'puffinbot',
                             'username': 'PuffinBot', 'perfs': {'blitz': {'games': 0, 'rating': 2000,
                             'rd': 500, 'prog': 0, 'prov': True}, 'bullet': {'games': 0, 'rating': 2000,
                             'rd': 500, 'prog': 0, 'prov': True}, 'correspondence': {'games': 0,
                             'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}, 'classical': {'games':
                             0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}, 'rapid': {'games':
                             0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}}, 'title': 'BOT',
                             'createdAt': 1701119375846, 'profile': {'bio': 'A bot written in
                             C#!\r\n\r\nPlease report any issues in the Github below.', 'links':
                             'https://github.com/kurt1288/Puffin'}, 'seenAt': 1701143624161, 'playTime':
                             {'total': 0, 'tv': 0}, 'url': 'https://lichess.org/@/PuffinBot', 'count':
                             {'all': 0, 'rated': 0, 'ai': 0, 'draw': 0, 'drawH': 0, 'loss': 0, 'lossH':
                             0, 'win': 0, 'winH': 0, 'bookmark': 0, 'playing': 0, 'import': 0, 'me': 0},
                             'followable': True, 'following': False, 'blocking': False, 'followsYou':
                             False}, 'config': <config.Configuration object at 0x0000017AC486BEE0>,
                             'challenge_queue': <ListProxy object, typeid 'list' at 0x17ac48c8730>,
                             'correspondence_queue': <AutoProxy[Queue] object, typeid 'Queue' at
                             0x17ac48f4d90>, 'logging_queue': <AutoProxy[Queue] object, typeid 'Queue' at
                             0x17ac48f5030>, 'game_id': 'fI8ENsiD'}
                    DEBUG    Exception: Traceback (most recent call last):                                lichess.py:65
                               File "C:\Python310\lib\site-packages\backoff\_sync.py", line 105, in retry
                                 ret = target(*args, **kwargs)
                               File "E:\Documents\LichessBot\lichess-bot.py", line 580, in play_game
                                 engine.get_opponent_info(game)
                               File "E:\Documents\LichessBot\engine_wrapper.py", line 384, in
                             get_opponent_info
                                 opponent = chess.engine.Opponent(name=game.opponent.name,
                             AttributeError: module 'chess.engine' has no attribute 'Opponent'
MarkZH commented 11 months ago

It looks like an old version of the python-chess dependency was installed. After activating the virtual environment (venv\Scripts\activate), try running pip install -r requirements.txt (or python3 -m pip install -r requirements.txt) again.

kurt1288 commented 11 months ago

I think the problem was actually that I was starting the bot outside of the virtual environment. In the past I was able to do that, but it seems like that's changed? Once I started the bot inside the venv, it seems to be working fine.