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?

2
  • 6
    Why do you say "common.Executive" when that is NOT the path to the module? Commented May 18, 2011 at 19:58
  • 1
    Also, see the documentation on packages: docs.python.org/tutorial/modules.html#packages Commented May 18, 2011 at 19:59

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

which module? Executive or ExecutiveTest?
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( )

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.