How do I make a Python script executable on Unix?

You need to do two things: the script file’s mode must be executable and the first line must begin with #! followed by the path of the Python interpreter.

The first is done by executing “chmod +x scriptfile” or perhaps “chmod 755 scriptfile.

$ chmod +x myscript.py

The second can be done in a number of ways. The most straightforward way is to put

#!/usr/local/bin/python

as the very first line of your file, using the pathname for where the Python interpreter is installed on your platform.

If you would like the script to be independent of where the Python interpreter lives, you can use the “env” program. Al