Contents of my project is like this
C:/{user_name}/my_project/
│ bar.sh
├─scripts/
│ │ bar.sh
│ │
│ └─bar/
│ bar.sh
│
└─src/
foo.py
and Content of all of bar.sh is
python src/foo.py
so if I run from C:/{user_name}/my_project/ directory, bar.sh works.
bash bash.sh
bash scripts/bar.sh
bash scripts/bar/bar.sh
However, after moved to scripts directory, below command does not work because bar.sh tries to find /my_project/sciprts/src/foo.py
bash bar.sh
I understand we can add my_project directory to PYTHONPATH by editing window's envrionmental valiables to solve this. However, I would like to avoid this because {user_name} can be varied and this envrionmental is shared by many guys.
Therefore I am looking for a good way to add my_project directory to PYTHONPATH by adding same line(s) to bar.sh. Do you know such a magic command?
python ../src/foo.py?cd "$(dirname "$0")/..". Dunno if that works on Windows, though.PYTHONPATHis the solution here. Instead, I would modify yourbar.shto add thesrcdirectory toPATHand then callpython foo.pydirectlyPYTHONPATHat a System level variable because that doesn't vary depending on the user name. Here's an old answer of mine on the topic (although exactly how to do things has changed). Here's another.