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 script.py (instead of python script.py).


5 Answers 5


There are two things you need to do:

  • Make sure the file is executable: chmod +x script.py
  • 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:



  • 35
    Generally it's a better idea to use #!/usr/bin/env python, in case the user has a local build of python (eg, in /usr/local/bin) which they'd rather run the script with.
    – sapi
    Oct 20, 2014 at 3:30
  • 4
    @sapi Not according to Debian it isn't, at least in their dev policies. If you are writing your own scripts, you can accept the risk of course, it is just better to be explicit. If you want the local one, choose it in the shebang.
    – Paul
    Oct 20, 2014 at 4:12
  • 3
    It's not bash that reads the file when executing...
    – mike3996
    Oct 20, 2014 at 5:52
  • 1
    @progo This is true - note that if you see an answer that you think would benefit from improvement, go ahead and edit it, improvements are always welcome
    – Paul
    Oct 20, 2014 at 9:24
  • And you'll have to do ./script.py, not script.py Oct 21, 2014 at 12:56

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] 


#!/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.


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.


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 script.py

To run the script:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .