Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 981
Bryan Avatar asked Mar 15 '26 16:03

Bryan


1 Answers

Firstly, your directory tree should be rather like this:

../
   /src
      /modules
        __init__.py
        lyrics.py 
   /tests
        test_lyrics.py 

References

  • https://github.com/pypa/sampleproject
  • What is the best project structure for a Python application?

Then, as mentioned in the previous comments, if executing in the command line from the project root folder, set the PYTHONPATH environment variable

export PYTHONPATH=./src 
like image 59
hpr Avatar answered Mar 17 '26 07:03

hpr