stephanos
stephanos

Reputation: 186

Python script won't run

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')

Upvotes: 4

Views: 9266

Answers (2)

rodrigo
rodrigo

Reputation: 98348

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.

Upvotes: 9

Michael Markert
Michael Markert

Reputation: 4026

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).

Upvotes: 5

Related Questions