0

I have installed Python 2.7 and trying to use Twitter package. I have installed the 3 pre-requisite packages successfully... But somehow getting this error:

>>> import twitter
>>> api = twitter.Api()
Traceback (most recent call last):
  File "<pyshell#30>", line 1, in <module>
    api = twitter.Api()
AttributeError: 'module' object has no attribute 'Api'

The I tried this version but got the same error:

>>> api = twitter.Api(consumer_key='consumer_key',
                  consumer_secret='consumer_secret',
                  access_token_key='access_token',
                  access_token_secret='access_token_secret')

Traceback (most recent call last):
  File "<pyshell#31>", line 1, in <module>
    api = twitter.Api(consumer_key='consumer_key',
AttributeError: 'module' object has no attribute 'Api'

I have installed 3 packages for twitter namely: python-twitter-0.8.5, python-twitter-1.0, twitter-1.10.0

and the output of the command is as below:

>>> twitter.__file__
'C:\\Python27\\lib\\site-packages\\twitter-1.10.0-py2.7.egg\\twitter\\__init__.pyc'

Should I be uninstalling something? I have renamed twitter.py files in python-twitter-0.8.5 and python-twitter-1.0 but still getting the error...

user2607677
  • 240
  • 1
  • 3
  • 13
  • What does `twitter.__file__` tell you you imported? You probably have another file called `twitter.py` in your current working directory. Rename that, it is masking the module. – Martijn Pieters Jul 23 '13 at 08:55

1 Answers1

0

You installed a different Twitter API module; you installed twitter 1.10.0, not python-twitter. The APIs between the two projects differ significantly:

import twitter

t = twitter.Twitter(
        auth=twitter.OAuth(OAUTH_TOKEN, OAUTH_SECRET,
                   CONSUMER_KEY, CONSUMER_SECRET)
       )

You may want to uninstall twitter and install python-twitter instead.

However, if all you need is a good Twitter API package for Python, take a look at the list that Twitter maintains. Tweepy and a different python-twitter package are under active maintenance.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Thanks, but the issue with Python-twitter that I see is that there are 2 such packages... python-twitter-0.8.5 & python-twitter-1.0 and moreover both of them supports Python 2.4 and not Python 2.7. So until I had installed twitter1.10 package, it was complaining that Python 2.4 does not exist... – user2607677 Jul 23 '13 at 09:21
  • @user2607677: updated with better alternatives. There are some conflicting packages around. – Martijn Pieters Jul 23 '13 at 09:26