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
There are two things you need to do:
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:
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
If you want the environment to find python for you.
You will also be required to make the script executable
chmod +x script[.py]
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.