I have read through already answered similar questions such as this.
I have been facing similar issue in my modules. However, when I make the python script executable with chmod
and copy it to /usr/local/bin
, I can run the script by calling its name.
What changes when I make it executable? Why doesn't it work otherwise?
Asked
Active
Viewed 36 times
0

Chinmay Bhoir
- 11
- 1
- 2
-
1add path to .bashrc file – Jay Shankar Gupta Feb 21 '18 at 11:14
-
I did not add anything to .bashrc, but the error vanishes after I make it executable. What exactly is the change? – Chinmay Bhoir Feb 21 '18 at 11:17
-
if you add below line to .bashrc you can run your code from anywhere in terminal – Jay Shankar Gupta Feb 21 '18 at 11:18
-
I don't want to do that. Please read my question again. – Chinmay Bhoir Feb 21 '18 at 11:19
-
when you make it executable then you can access that script as application also. – Jay Shankar Gupta Feb 21 '18 at 11:21
-
Yes I know. But why doesn't it throw the error after I make it executable? It only throws error when I run it with `python` – Chinmay Bhoir Feb 21 '18 at 11:23
1 Answers
0
I found the answer.
My python script was compatible with python 3, but not python 2. When I ran with python 2 (i.e. by command python
), it throws AttributeError.
The script works when made executable because of #!/usr/bin/env python3
in my script, telling the shell which interpreter to use.

Chinmay Bhoir
- 11
- 1
- 2