The 'module' object does not have the 'twitter' attribute

I try to follow the example on page 5 of the book: Creation of a Social Network by O'Reilly. I meet the following error:

>>> import twitter >>> twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1') 
  Traceback (most recent call last):
   File "", line 1, in 
 AttributeError: 'module' object has no attribute 'Twitter'

What could be?

+4
source share
2 answers

Check the twitter.__file__ (after you imported the twitter). I assume that either you have a broken version of Twitter, or you created a file called twitter.py in the same directory from which you are working, from blocking the installed module from loading.

If twitter.__file__ looks good (indicating where your installed modules should be instead of the local directory), try easy_install -U twitter reinstall it.

+4
source

It works for me. I installed twitter via easy_install , which has the latest version (1.6.1) installed. dir(twitter) also lists twitter here.

You can remove the twitter package from the site packages and try again.

+4
source

All Articles