Knowledgebase: Application Notes
Running Python scripts from anywhere under Windows
Posted by Micah Simonsen, Last modified by Micah Simonsen on 17 August 2017 11:53 AM

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:
 
> foo.py
 
instead of needing to type:
 
> python path\to\foo.py
 
Please, follow these steps:
  1. Create directory to put all your python scripts in. E.g. "C:\Users\Your Name\My Scripts"
  2. Copy all your python scripts into this directory
  3. Add the path to this directory in Windows "PATH" system variable:
    Open Explorer
    Right-click on "My Computer"
    Click "Properties"
    Click "Advanced system settings"
    Select tab "Advanced"
    Click "Environment Variables"
    Select "Path"
    Click "Edit"
    Click "New"
    Add path to the created directory, e.g "C:\Users\Your Name\My Scripts"
  4. Run or restart "Anaconda Prompt"
  5. Type "your_script_name.py"
  6. 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"
    Click "Open"
    Click "OK"
  7. You should be able to run any of your python scripts from any directory now.
(2 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments: