Making Python scripts executable in Windows

To launch a Python program myprog.py on Windows, you normally have to type

python myprog.py

After installing the Python Launcher, you can just type

myprog.py

Linux/Mac

./myprog.py

is governed by the shebang on the first line of myprog.py

#!/usr/bin/env python

Don’t specify a shebang like #!/usr/bin/python except for specific situations like GNU Radio scripts where you specifically want system Python in some (but not all) cases.

Windows Python Launcher Installation

Unless you use CPython directly (most people don’t, most people use something like Anaconda Python), so you need to install Python Launcher on Windows.

  1. Download the most recent launchwin*.amd64.msi
  2. double click the .msi file to install Python Launcher.
  3. open a new Command Prompt and type
    py
    

    and verify your desired Python prompt is seen.

Now typing in Windows Command Prompt

myprog.py

Python runs myprog.py as expected.

Leave a Comment