4

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')
1
  • 1
    also make sure to make your file executable chmod u+x aek.py Commented Sep 9, 2011 at 21:06

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

Comments

5

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.