0

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?

John Y
  • 14,123
  • 2
  • 48
  • 72
Blade3
  • 4,140
  • 13
  • 41
  • 57

2 Answers2

2

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.

Adam Byrtek
  • 12,011
  • 2
  • 32
  • 32
1

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( )

Community
  • 1
  • 1
Sheena
  • 15,590
  • 14
  • 75
  • 113