Run Python scripts without explicitly invoking `python`

Super User Asked by user2018084 on January 1, 2022

I’m using Debian Linux.

I was wondering if there was a way to configure to run all Python scripts in the terminal by typing (instead of python

5 Answers

Add the following line to the top of the script to run default python interpreter:


To specify the python version then add the version number after python:


If you have a local build of python and would like to use that:

#!/usr/bin/env python

Then you will need to make your script executable by running the following command:

chmod +x

To run the script:


Answered by WMRamadan on January 1, 2022

Use a shebang line at top of your script as below:


Update appropriate python version on which you want to execute the script. e.g. For python 3.6 its


for default interpreter


Note: Make sure script has executable permission.

Answered by Suraj Bora on January 1, 2022


#!/usr/bin/env python

This will ensure that the python the user expects to be used will be the one that runs the script. This is especially important if the user is using virtualenv to have a specific version of python in a given environment.

Answered by Cory Klein on January 1, 2022

Under linux you can simply use the hashbang(aka shebang). Add the line


if you want to execute the default python interpreter.


to use some specific version, or

#!/usr/bin/env python

If you want the environment to find python for you.

You will also be required to make the script executable

chmod +x script[.py] 

Answered by Gaurav Joseph on January 1, 2022

There are two things you need to do:

  • Make sure the file is executable: chmod +x
  • Use a shebang to let the kernel know what interpreter to use. The top line of the script should read:


    This assumes that your script will run with the default python. If you need a specific version, just specify in the shebang:


Now you can type:


if the script is in your current directory, or:

if the location of the script happens to be in your PATH, or:



Answered by Paul on January 1, 2022

Add your own answers!

Related Questions

How to Set Up an SFTP Reverse Proxy

0  Asked on January 23, 2021 by subbarao-avl


How do I play a keynote powerpoint on one display?

0  Asked on January 23, 2021 by busaruba2011


Splitting a video with ffmpeg loses first video frames

0  Asked on January 22, 2021 by guy-ellis-hreinberg


Excel If Statements

1  Asked on January 22, 2021 by britney


MS Dynamics CRM 2015 assigning tasks to non CRM users

2  Asked on January 21, 2021 by asneineh


facebook like button not displayed in firefox

1  Asked on January 21, 2021 by leungwensen


AMD Raid and Dual Boot

0  Asked on January 21, 2021 by sn0wtroopeer


SourceSafe Visual Web Developer 2010

2  Asked on January 19, 2021 by sixfoot-studio


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP