I have the follwing folder structure of my Python project:
Project is the base directory.
Project
|------package1
| |--------module1.py
| |--------module2.py
|------package2
| |--------module3.py
| |--------module4.py
|------Test
| |-----test.py
The contents of test.py
is:
import package1.module1
When I run test.py, the below error is thrown:
ModuleNotFoundError: No module named 'package1'
I am aware that the package/module search would contain the directory where the script is run.
So in this case, package1 directory path is NOT included; hence the error is thrown.
Adding the path of package1 via sys.path.append() is not a nicer way whenever we do imports.
I see that many projects import modules/packages in the above mentioned way only.
I am wondering how they work actually.
can I get some guidance on how to make the above setup work.
Thanks