google-deepmind / open_spiel

OpenSpiel is a collection of environments and algorithms for research in general reinforcement learning and search/planning in games.
Apache License 2.0
4.23k stars 932 forks source link

Python Import Issues - Windows Build #1257

Open Gronchii opened 2 months ago

Gronchii commented 2 months ago

I have managed to get this to build successfully on windows after some changes for MSVC, but I am not able to import into python. I followed the windows build guide and added the 2 paths to my PYTHONPATH:

-D:\OpenSpiel\open_spiel\open_spiel\out\build\x64-Debug -D:\OpenSpiel\open_spiel\open_spiel\out\build\x64-Debug\python

However, I now have 2 issues when trying to import into python script.

The first is when I try to import pyspiel through python

import pyspiel

I get this error: ImportError: DLL load failed while importing pyspiel: The specified module could not be found.

I do see where pyspiel.pyd is present inside build\x64-Debug\python, and when I remove from PYTHONPATH it no longer is able to find the module at all.

The second python issue is when I try to run open_spiel\python\examples\example.py I get a different error relating to attempting to import from open_spiel.python

Traceback (most recent call last): File "d:\OpenSpiel\open_spiel\open_spiel\python\examples\example.py", line 24, in <module> from open_spiel.python import games # pylint: disable=unused-import ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ModuleNotFoundError: No module named 'open_spiel'

Any insight would be appreciated

lanctot commented 2 months ago

For the second problem, I think you also need to have the top-level source directory as well in PYTHONPATH, e.g. the equivalents of step 5 in these instructions: https://github.com/google-deepmind/open_spiel/blob/master/docs/install.md#summary

Based on your paths above that would be D:\OpenSpiel\open_spiel\open_spiel.

For the first problem, I don't know how to solve it. If the DLL is being built and it's in the PYTHONPATH then Python should be able to load it. Possibly Python is not setup to look into the PYTHONPATH, but that worked for me last time I tried it.

Gronchii commented 2 months ago

You are correct, adding top-level did resolve the open_spiel.python import. The pyspiel import issue looks to be due to conda, the dll loads fine when run outside of a conda environment so I will see if I can get that sorted

Thanks