evogym icon indicating copy to clipboard operation
evogym copied to clipboard

ModuleNotFoundError: No module named 'evogym.simulator_cpp'`

Open ndr09 opened this issue 3 years ago • 4 comments

I followed the instructions and installed Evogym on my pc (win 11). However, I have the following two problems and for both I will use the evogym/tutorials/basic_api.py file as reference:

  1. from pycharm it give the following error, while from the terminal it executes correctly Traceback (most recent call last): File "C:/Users/opuse/Desktop/evogym/tutorials/basic_api.py", line 1, in <module> from evogym.envs import * File "C:\Users\opuse\Desktop\evogym\evogym\__init__.py", line 2, in <module> from evogym.sim import EvoSim File "C:\Users\opuse\Desktop\evogym\evogym\sim.py", line 9, in <module> import evogym.simulator_cpp ModuleNotFoundError: No module named 'evogym.simulator_cpp'
  2. If I move the basic_api.py out from the tutorials folder, hence in evogym/basic_apy.py, it will not execute returning the same error from 1

Thanks, Andrea

ndr09 avatar Jul 06 '22 14:07 ndr09

Same as #5 , everyone with windows hits this error

Titanium2099 avatar Jul 06 '22 20:07 Titanium2099

Same as #5 , everyone with windows hits this error

I have successfully installed Evogym on Ubuntu and Centos, but I don't know how to fix this issuse on Windows.

Yuxing-Wang-THU avatar Jul 07 '22 09:07 Yuxing-Wang-THU

so, ideally, if I use the HPC of my university which is linux based, I should not have problem calling from an outside folder? Or it depends also on the distro?

Edit: for both the problems adding the following code before importing the evogym makes the code run. Where folder is the position on the disk where you cloned the repo. in particular part 0 makes Pycharm able to run the code, while adding part 1 makes the code also running from a diverse folder. Note I am not sure of why this happens and I find the solution trying printing sys.path and looking for the differences

#### part 0
for i in range(len(sys.path)):
    if sys.path[i] == _folder_:
        pos.append(i)

if len(pos) > 0:
    for i in sorted(pos, reverse=True):
        sys.path.pop(i)
##### part 1
curr_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.join(curr_dir, 'evogym')
sys.path.insert(0, root_dir)

Thanks

ndr09 avatar Jul 11 '22 09:07 ndr09

This can happen if python looks for evogym in the current directory (for example, the source code), and not in its installed location in dist-packages. Notably, this will happen when using python setup.py install instead of pip install .. The compiled file simulator_cpp.py is only made in the dist-packages version

You can copy the generated simulator_cpp.py from the dist-packages installed version into your local directory or copy the full version locally if you used python setup.py install. However, using pip is probably safer and is possible with the modifications proposed in #27.

d9w avatar Apr 20 '23 04:04 d9w