Reputation: 11309
New to Python. I'm on Windows and Python2.7.
I have confirmed that my directory is setup in PYTHONPATH by looking in sys.path from IDLE.
import sys
print(sys.path)
This shows me that c:\users\owner\documents\PythonProjects is definitely in the path. Furthermore in that directory I have a .py file which can be imported into IDLE.
The trouble is c:\user\owner\documents\PythonProjects\testPackage\test.py is not loading. The error is ImportError:No module named testPackage.test.
I have tried an empty __init__.py
as well as an __init__.py
with some trivial code inside. The __init__.py
is in the PythonProjects folder as it should be. Why am I getting this error?
Upvotes: 1
Views: 4243
Reputation: 5133
There must be an __init__.py
file in every directory, so if your structure is:
projects/
TestProject/
__init__.py
test.py
And the path to projects
is on your PYTHONPATH, then you should be able to import the test
module.
Upvotes: 0