Why are these Python scripts giving syntax errors?

Question:

I am trying to install python on windows, and this is my first day on python. Install goes well on windows 7 x64. But almost all scripts fails. I am trying to install celery and running following command on celery folder.

python setup.py build

and it fails, following is an error

  File "setup.py", line 40
except ImportError, exc:
                      ^
SyntaxError: invalid syntax

also following fails, which is valid print command i think.

>>> print 'a'
  File "<stdin>", line 1
    print 'a'
            ^
SyntaxError: invalid syntax

I am sure i am missing something here. Any idea what makes it fail?

Edit:
Below is summary of tasks i had to go through to get python working, made notes for myself but putting it here as well if it can help anyone

Install python and celery
=========================
-celery does not work with python3, so install latest python2
-install windows install for python2
-add C:python2X to %PATH%
-set python path for lib
        set PYTHONPATH=%PYTHONPATH%;c:python2x
-install setuptools
    http://pypi.python.org/pypi/setuptools
    for x64 install does not work use
        python setup.py install
-then can use easy_install
-now just use easy_install to install everything
Asked By: mamu

||

Answers:

A likely cause is version incompatibility, as Vincent Savard pointed out. Python 3 is not backwards compatible with Python 2
if print 1 doesn’t work, but print(1) does, then you are running python 3, which seems to be the case

Answered By: Martijn

Yeah you’re probably running python 3. Try print("hello world")

If that works then you’re running python 3

Answered By: Pwnna

for Python 3 the syntax has been changed so

Change from except exc, var to except exc as var.

viz ( http://docs.python.org/release/3.1.3/whatsnew/3.0.html )

Answered By: Jirka

except ImportError, exc:
should be
except ImportError as exc:

Answered By: djangomaster
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.