Reputation: 4360
I have a module(Executive.py) that I am trying to import into another module I am working on (ExecutiveTest.py). The directory structure is like so:
src/
common/
python/
Executive.py
tests/
ExecutiveTest.py
In ExecutiveTest.py, I have the following line:
from common.Executive import Executive
I get an error saying:ImportError: No module named common.Executive
How do I correct this import error?
Upvotes: 0
Views: 125
Reputation: 16212
I found a similar post here. it looks like you can define the path that python refers to when looking for stuff to import. Something like:
sys.path.append( )
Upvotes: 1
Reputation: 12202
You have to have an __init__.py
file in the root of your package (it can be empty). Also, your module hierarchy has to reflect the directory structure, so python
and tests
should be part of the import as well.
Upvotes: 2