Run Python Scripts Without Invoking `Python`

Posted on July 31, 2019 at 11:59 am

To nromally run python scriupts you need to invoke `python`, i.e:

python script.py

However, if you include this text in the first line of your python script:

#!/usr/bin/python

Then you can run your python script with just:

./script.py

Of course, you’ll need to first set +x permissions:

chmod +x script.py

If you need to run your script with a specific python version, use:

#!/usr/bin/python2.7

In case you have a local build of python, use:

#!/usr/bin/env python

Receive updates via email

Other Posts

Updated Posts