I have a directory structure:
root_dir
├── src
│ └── p1.py
└── lib
├── __init__.py
├── util1.py
└── util2.py
I want to run src/p1.py
which uses lib/util1.py
using an import statement import lib.util1 as u1
.
It runs fine when I use PyCharm, but I want to also run it from command line. How can I run the program from command line?
I have tried cd root_dir
then python src/p1.py
.
But it produces the following error:
Traceback (most recent call last):
File "./src/p1.py", line 1, in <module>
import lib.util1 as u1
ImportError: No module named lib.util1
How can I run the python program src/p1.py
from the command line?
Edit: Based on the suggestion from @Sumedh Junghare, in comments, I have added __init__.py
in lib folder. But still it produces the same error!