Im trying to import a module from a different sub directory in Python 3 and I'm having trouble getting the script running. The current file structure I have is:
/lets_import
__init__.py
/app
__init__.py
main.py
server.py
/tests
__init__.py
tests_main.py
tests_main.py
imports a function from server.py
like this:
from app.server import add
(add is the function being imported from server.py)
init files are empty. They are there so that each sub dir is seen as a package.
When I run tests_main.py
I get the following error
File "tests/tests_main.py", line 2, in <module>
from myapp.server import add
ImportError: No module named 'myapp'
I tried running it from the root level folder like this python test/tests_main.py
but still got the same error.
Is there a way to do this without having to manipulate PYTHONPATH?