Python script will not run

I have some scripts in the ~ / Scripts folder that I added to the path. So I tried to check if I can run them just by calling them. I have python 3.1 over Linux Mint 11.

user@pc ~/Scripts $ python aek.py AEK user@pc ~/Scripts $ aek.py /home/user/Scripts/aek.py: line 1: syntax error near unexpected token `'AEK'' /home/user/Scripts/aek.py: line 1: `print('AEK')' 

Code is just one line:

 print('AEK') 
+4
source share
2 answers

You need to add the first line to the script:

 #!/usr/bin/python 

Or any interpreter you want to use. If not, the shell (possibly bash) will think that it is a shell script and a throttle.

If you want to get the python interpreter from the path, do this instead:

 #!/usr/bin/env python 

For more information, contact shebang .

+9
source

The error is not a python error, but a shell error.

You must add the shebang line if you do not run them through the python executable.

And this is definitely not a python2 ↔ python3 conflict. python2 does a great job with the partner (but there are angular cases where it breaks).

+5
source

All Articles