Running Python 3.6.1, and I'm trying to get a file (world.py
) to import from another package in my project.
My directory structure:
+-- test_project
| +-- sub_project1
| | +-- __init__.py
| | +-- hello.py
| +-- sub_project2
| | +-- __init__.py
| | +-- world.py
hello.py
:
def say_hello():
return("Hello ")
world.py
:
from test_project.sub_project1.hello import say_hello
print(say_hello() + "world!")
When I go into the sub_project2
directory and run world.py
, I keep getting this:
ModuleNotFoundError: No module named 'test_project'
I've tried rewriting the import statement to from sub_project1.hello import say_hello
. I've also tried having the test_project
directory in my PATH environment variable. I've tried having the test_project
's parent directory in my PATH. I've tried having the sub_project2
's directory in my PATH. I've searched for answers online and can't work out what I'm missing.
What am I doing wrong here?