To make Python scripts runnable from any location under Windows:
To call python scripts directly from the anaconda console command prompt, e.g., to invoke the script “foo.py” by typing:
instead of needing to type:
> python path\to\foo.py
Please, follow these steps:
- Create directory to put all your python scripts in. E.g. "C:\Users\Your Name\My Scripts"
- Copy all your python scripts into this directory
- Add the path to this directory in Windows "PATH" system variable:
Right-click on "My Computer"
Click "Advanced system settings"
Select tab "Advanced"
Click "Environment Variables"
Add path to the created directory, e.g "C:\Users\Your Name\My Scripts"
- Run or restart "Anaconda Prompt"
- Type "your_script_name.py"
- For the first time, windows asks what application to use to run *.py files.
Select python in Anaconda directory: make sure check box "Always use this app to open .py files" is checked
Click "More Apps"
Click "Look for another app on this PC"
Find path to anaconda python, e.g. "C:\Users\Your Name\Anaconda3\python"
- You should be able to run any of your python scripts from any directory now.