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?
-
6Why do you say "common.Executive" when that is NOT the path to the module?S.Lott– S.Lott2011年05月18日 19:58:28 +00:00Commented May 18, 2011 at 19:58
-
1Also, see the documentation on packages: docs.python.org/tutorial/modules.html#packagesJoe Kington– Joe Kington2011年05月18日 19:59:38 +00:00Commented May 18, 2011 at 19:59
2 Answers 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
Adam Byrtek
12.2k2 gold badges35 silver badges33 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Blade3
which module? Executive or ExecutiveTest?
lang-py