2

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
  • Yes, your understanding is correct, PYTHONPATH does not affect script search path. You can create an env var MY_SCRIPT=/full/path/to/script.py and then run python "$MY_SCRIPT" wherever you want. Commented Mar 31, 2014 at 21:33

1 Answer 1

4

yes, add it to your PYTHONPATH as you are doing, but you cannot invoke it with python foo.py, instead, use python -m foo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.