Ideally you should run a python script from the top level package (which imports and/or runs code that starts the whole application) like the following:
Test
├── package1
│ └── script1.py
│ └── __init__.py
├── package2
| └── script2.py
| └── __init__.py
|___ run.py
Then run python3 run.py
When you import from package1.script1 import *
, you are saying to Python to search the packages from the path the main script was run. Thus it assumes you are searching package1
from package2
. If you place package1
inside package2
and run python3 script2.py
, it will also work.
Test
├── package2
├── package1
│ └── script1.py
│ └── __init__.py
└── script2.py
└── __init__.py
If you still want to run from script2 with the same directory structure then you have to either be in the Test
directory and run python3 package2/script2.py
or modify the python path.