How to give executable permission to all Python scripts in Linux?

Ted James
2 min readJun 5, 2024

Suppose I have a python script called a.py like this:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author : Bhishan Poudel
# Date : Jul 13, 2016


# Imports


# Script
print("hello")

I can run this scripts in two ways:
Using python interpreter:

python3 a.py

Changing permission

chmod a+x a.py; ./a.py

QUESTION
How can I run any new or old python scripts without using chmod a+x script_name all the times.

I have root access and user access both to my computer.

Basically i want executable permission to all the .py files, how can we do so?

I tried different shebangs such as:

#!/usr/bin/python3
#!/usr/bin/env python3
#!/usr/local/bin/python3
#!/usr/local/bin/env python3

The python interpreter is also in the $PATH. The output of echo $PATH is following:

/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/opt/local/bin:/Users/poudel/phosim:/Users/poudel/Applications:/usr/local/octave/3.8.0/bin:/Users/poudel/Applications/Geany.app/Contents

--

--

Ted James

The world is my office, and every destination is my inspiration