pytorch / ELF

ELF: a platform for game research with AlphaGoZero/AlphaZero reimplementation
Other
3.37k stars 566 forks source link

Fixing "ImportError: dynamic module does not define module export function (PyInit__elf)" #98

Open hanysz opened 6 years ago

hanysz commented 6 years ago

I think I've solved this, but I'm posting here in case it helps someone else.

Context: I already have a working python/pip installation and didn't want to install conda, so I tried downloading the Python dependencies using pip3 instead. This seemed to work (apart from there being no pip package for zeromq -- this appears to be included within pyzmq), as I was able to build without errors.

Problem: gtp.sh gives a string of error messages ending with "ImportError: dynamic module does not define module export function (PyInit__elf)". This is a bit cryptic (googling for "dynamic module" doesn't throw up anything useful).

Explanation: "Dynamic module" in this context refers to Python loading a module from a compiled .so file instead of from a .py file. The error is caused by the *.so files being linked against Python 2 libraries instead of Python 3 libraries.

Solution:

  1. Before running make, do cmake -DPYTHON_EXECUTABLE=/usr/bin/python3
  2. For some reason, this causes executables to be created in ${ELF_DEVELOPMENT_ROOT}/elf and ${ELF_DEVELOPMENT_ROOT}/elfgames, rather than under ${ELF_DEVELOPMENT_ROOT}/build. So you need to edit scripts/devmode_set_pythonpath.sh and delete the characters "build/" twice.
  3. On my non-conda system, PYTHONPATH isn't set by default, and setting it causes python to forget the default path. I fixed this by appending the output of python3 -c "import sys; print(':'.join(sys.path))" to scripts/devmode_set_pythonpath.sh
jleagle94 commented 5 years ago

Hello, Just wanted to say your step one helped me resolve my issue (same exact error just different software called CRPropa). Thanks a bunch and hopefully those facing the issues I had with the same software can come here to have the same success.

avichapman commented 4 years ago

I'm seeing a similar issue. However, I'm pretty sure my build is against Python 3. I've even been able to see the PyInit_XXX entry when I grep into the *.so file.

If it was linked against Python 2, would the 'PyInit_XXX' be there?