I have some scripts in the folder ~/Scripts which I have added to the path. So I tried to test 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')'
The code is just this one line:
print('AEK')
You need to add the very first line in your script:
#!/usr/bin/python
Or whatever interpreter you want to use. If not, the shell (probably bash) will think that it is a shell script and choke.
If you want to get the python interpreter from the path, do instead:
#!/usr/bin/env python
For extra information, see shebang.
The error is not a python error but a shell error.
You should add a shebang line if you don't run them via the python executable.
And it most definitely is not a python2 <-> python3 conflict. python2 handles parens here quite well (but there are corner cases where it breaks).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With