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.6k2 gold badges51 silver badges76 bronze badges
asked May 18, 2011 at 19:56
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.

answered May 18, 2011 at 19:58
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( )

answered May 18, 2011 at 20:05

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.