pythonpython-3.ximporterror

Receiving Import Error: No Module named ***, but has __init__.py


I understand that this question has been asked several times but after reading them, and making the suggested fixes, I'm still stumped.

My project structure is as follows:

Project
      |
      src
        |
         root - has __init__.py
            |
            nested - has __init__.py
                  |
                  tests - has __init__.py
                  |
                  utilities - has __init__.py
                  |
                  services - has __init__.py

I've successfully run a unittest regression class from Eclipse without any issues.

As soon as I attempted to run the same class from the command-line (as other users who will be running the suite do not have access to Eclipse) I receive the error:

ImportError: No module named 'root'

As you can see from above, the module root has an __init__.py All __init__.py modules are completely empty.

And assistance would be gratefully received.


Solution

  • Try adding a sys.path.append to the list of your imports.

    import sys
    sys.path.append("/Project/src/")
    import root
    import root.nested.tests