'How to solve "no module named" problem for Python when using Environment Modules package?
I am using a software environment loaded with the Environment Modules package (not to be confused with Python modules) using module load my_env. Within this environment, I am attempting to run a python script that imports a self-defined Python module using import my_py_module. When I tried to run this script, an error is reported saying
ModuleNotFoundError: No module named 'my_py_module'
How can I solve this issue?
Solution 1:[1]
The my_env modulefile should update the PYTHONPATH environment variable to add the location of the my_py_module.
$ cat /path/to/modulefiles/my_env
#%Module
append-path PYTHONPATH /path/to/my_py_module/location
Once such modulefile is loaded, you should be able to run a python script that imports my_py_module:
$ module use /path/to/modulefiles
$ module load my_env
$ python myscript.py
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xavier Delaruelle |
