'Python Twitter library: cannot import it
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
Solution 1:[1]
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.
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |
Solution 2 | Pablo Guerrero |