'What is causing Import Error: "no module named modules"?
I am working on my first open source project.
While getting everything setup for the project, I followed the README.md step by step.
Now, I run into a problem. When I try to run a test and src scripts, I get the following error,
ImportError: No module named modules
Now, below is the file structure.
../
/modules
__init__.py
/src
lyrics.py
/tests
test_lyrics.py
lyrics.py import statements
import modules
def test_lyrics():
assert('lyrics' == modules.process_query('paradise lyrics')[0])
This is where the error "Import Error: modules not found".
Yes, all the requirements on the README were met.
If you want to take a look at the project, check it out on github.
Solution 1:[1]
It could be that your module's directory is not being read by your PYTHONPATH. To check this go to your home directory and look for a .bashrc or some kind of .profile file. You may have to use ls -a to see these hidden files. If you don't see your module's address listed, add this to the file:
export PYTHONPATH="${PYTHONPATH}:/my/module/path"
Make sure the address points to the directory with your highest-level __init__.py file as python uses it to read the directory as a python package.
Solution 2:[2]
Use python -m site to conveniently view the
effect of the $PYTHONPATH env var on sys.path.
Code authors will often assume that current directory is in your path:
$ export PYTHONPATH=.
If you intend to use . current directory,
then pay careful attention to which one's in use
at the time the script starts running.
You may want to view this value: os.getcwd()
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 | tooty44 |
| Solution 2 | J_H |
