0

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
mamu
  • 12,184
  • 19
  • 69
  • 92
  • 1
    You might try to execute a Python 3 program with Python 2. – Vincent Savard Oct 30 '10 at 15:53
  • 3
    *"python on windows does not work"* ... and I guess you are the first one to discover that issue? How about "Why am I getting a syntax error when I try to run this Python script?" – Sinan Ünür Oct 30 '10 at 15:55

4 Answers4

7

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

Martijn
  • 11,964
  • 12
  • 50
  • 96
  • and Gadarene upvoters: -1 `print(1)` works in any version of Python; it's equivalent to `print (1)` which is equivalent to `print 1` – John Machin Oct 31 '10 at 00:20
  • like I said before: It's not that `print(1)` doesn't work in newer versions of python 2 (I think 2.4), but that `print 1` doesn't work in python 3 – Martijn Oct 31 '10 at 08:18
1

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

djangomaster
  • 93
  • 1
  • 8
1

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 )

Jirka
  • 11
  • 1
-2

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

If that works then you're running python 3

Pwnna
  • 9,178
  • 21
  • 65
  • 91
  • 1
    -1 Utterly useless answer. If that works, you're running Python, period. Python 1 and Python 2 treat that as `print any_old_expression`, which in this case evaluates to `"hello world"` [tested with Python 1.5.2, 2.1, and 2.7] -- try it and see. The two syntax errors listed by the OP are conclusive evidence that the OP is trying to execute pre-3 script(s) with Python 3.x – John Machin Oct 31 '10 at 00:09
  • What I'm trying to say is that if print "something" doesn't work and print("something") works, you're running python 3. – Pwnna Oct 31 '10 at 16:59
  • Yeah i know that, print "seomthing" only works with python 2 or less – Pwnna Nov 02 '10 at 15:34