2

I'm trying this presumably basic thing of importing Python Twitter library.

First I got an error in line 52, saying he couldn't upload a json library. That line of code is part of script where the library decides which json library it should import based on Python's version. I commented all lines addressing other versions of Python than the one I'm using and it worked.

Then another error popped up:

 Traceback (most recent call last):   
    File "<pyshell#0>", line 1, in <module>
 import twitter
    File "C:\Python32\lib\twitter.py", line 3448
 except urllib2.HTTPError, http_error:
                         ^ SyntaxError: invalid syntax

This one I don't understand.

I tried importing this in versions 2.6, 2.7, 3.1 and 3.2.2, but none worked. In one I was asked for the oauth library, then oauth2. The first one I got right, the second one couldn't.

I think this should work in 3.2.2. Can anyone help me?

Thanks in advance

2
  • That exception you mentioned is a syntax error for Python 2 code that's trying to run in python 3. I can tell because of the except syntax. How did you install the package? easy_install or pip? Commented Sep 8, 2011 at 18:10
  • I had the same! I think it's a compatibility problem. The module works fine with python 2.7 but not with 3.1, 3.1 or 2.6 version.
    – user1938380
    Commented Dec 30, 2012 at 19:05

2 Answers 2

2

That exception you mentioned is a syntax error for Python 2 code that's trying to run in python 3. I can tell because of the except syntax.

From the project page:

Install the dependencies:

http://cheeseshop.python.org/pypi/simplejson
http://code.google.com/p/httplib2/
http://github.com/simplegeo/python-oauth2

from http://pypi.python.org/pypi/python-twitter/

easy_install python-twitter or pip install python-twitter should work.

0

I had to change the installed library to be able to import pytwitter on python 3:

pip uninstall python-twitter
pip install python-twitter-v2

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.