I am struggling with running python script in shell. I use PyCharm where is everything ok, but I want to run script without running PyCharm.
So my project folder is like:
data/
file.txt
main/
__init__.py
script.py
tools/
__init__.py
my_strings.py
I want to run main/script.py
, which start with from tools import my_strings
and working directory should be data/
.
My PyCharm config is:
- Script path:
<PROJECT>/main/script.py
- Working directory:
<PROJECT>/data
- Add content roots to PYTHONPATH: YES
- Add source roots to PYTHONPATH: YES
So I want to run main/script.py
in shell on Ubuntu. I tried:
PYTHONPATH=<PROJECT>
cd <PROJECT>/data
python3 ../main/script.py
But I just got: ImportError: No module named 'tools'