Say I have a script script.py located in a specific folder in my system. This folder is not available on PATH.
Assuming that I will always run script.py using python script.py, is there any way to run my script from anywhere on the system without having to modify PATH?
I thought modifying PYTHONPATH would do it, but it doesn't. PYTHONPATH seems to only affect the module search path, and not the script search path. Is my understanding correct?
1 Answer 1
yes, add it to your PYTHONPATH as you are doing, but you cannot invoke it with python foo.py, instead, use python -m foo.
PYTHONPATHdoes not affect script search path. You can create an env varMY_SCRIPT=/full/path/to/script.pyand then runpython "$MY_SCRIPT"wherever you want.