1

hi i am new to python and i got this error but i have installed twitter but it's giving this error

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

I don't know about this error as i have almost every package related to twitter

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

when i give this command python setup.py install_data it give error like this running install_data

Traceback (most recent call last) :
file "setup.py" ,line 47 , <module>
""" ,
File "C:\python26\lib\distutils\core.py" ,line 152 , in setup
dist.run_commands()
File "C:\python26\lib\distutils\dist.py" ,line 975 , in run_commands
self.run_command(cmd)
File "C:\python26\lib\distutils\dist.py" ,line 995 , in run_commands
command_obj.run
File "C:\python26\lib\distutils\command\install_data.py" , line 44 in run
For f in self.data_files

5 Answers 5

1

can you reinstall using,

sudo pip install twitter

or

sudo easy_install twitter

The old versions did not required OAuth but new one does. The documentation of the latest version requires these to initiate the API

>>> api = twitter.Api(consumer_key='consumer_key',

    consumer_secret='consumer_secret', access_token_key='access_token', access_token_secret='access_token_secret') 
Sign up to request clarification or add additional context in comments.

6 Comments

i am window 7 user and i think sudo is for linux ??
I think you can still do "easy_install twitter" use this link to install setuptools for windows packages.python.org/distribute/…
I'm seeing the same behavior as the OP on win7/64 and debian, both freshly installed (pip install -U twitter). import twitter;twitter.Api gives AttributeError. I haven't used the module before, but from reading the start of the docs, it looks like you might have to do an OAuth authentication dance first..?
Actually I had the old version which did not required OAuth stuff. I installed the latest one. The documentation of the new version mention doing this. >>> api = twitter.Api(consumer_key='consumer_key', consumer_secret='consumer_secret', access_token_key='access_token', access_token_secret='access_token_secret')
Apart from the search... Twitter requires tokens it is documented
|
1

Your mixed with libraries actually the problem is that your are reading library of python_twitter and installed twitter.You need select the correct documentation.This is documentation error nothing else.You installed correct library.

Comments

0

The error message "'module' object has no attribute 'Api'" means what it says: Python can't find anything named 'Api' inside the imported module 'twitter'.

Try dir(twitter) after the import statement. dir() will show what Python finds inside the object. If dir(twitter) shows an object called 'twitter', you may have to do something like from twitter import twitter.

4 Comments

['NoAuth', 'OAuth', 'Twitter', 'TwitterError', 'TwitterHTTPError', 'TwitterResponse', 'TwitterStream', 'UserPassAuth', 'all', 'builtins', 'doc', 'file', 'name', 'package', 'path', 'api', 'auth', 'dedent', 'oauth', 'oauth_dance', 'oauth_doc', 'read_token_file', 'stream', 'twitter_globals', 'write_token_file']
ImportError: cannot import name twitter
@munieb: Python is case sensitive. Notice that dir(twitter) contains 'Twitter', not 'twitter', and 'api', not 'Api'.
now i get this ['ACCESS_TOKEN_URL', 'AUTHORIZATION_URL', 'Api', 'CHARACTER_LIMIT', 'DEFAULT_CACHE', 'DirectMessage', 'Hashtag', 'List', 'REQUEST_TOKEN_URL', 'SIGNIN_URL', 'Status', 'StringIO', 'Trend', 'TwitterError', 'Url', 'User', '_FileCache', '_FileCacheError', 'author', 'builtins', 'doc', 'file', 'name', 'package', 'version', 'base64', 'calendar', 'datetime', 'gzip', 'httplib', 'md5', 'oauth', 'os', 'parse_qs', 'parse_qsl', 'rfc822', 'simplejson', 'sys', 'tempfile', 'textwrap', 'time', 'urllib', 'urllib2', 'urlparse'] why i get Twittererror in it
0

Where did you install the python twitter module from? I used http://code.google.com/p/python-twitter/source/browse/twitter.py, and it has an Api class.

>>> import twitter
>>> api = twitter.Api()

1 Comment

i installed it from python official site . well i copy this code but it not run
0

You've installed the wrong twitter library. I'm guessing you've done

pip install twitter

you should uninstall that library:

pip uninstall twitter

and install the correct(*) one

pip install python_twitter

(*) by correct I mean the one you're reading the documentation to :-)

11 Comments

I tested it on win7, so yes, it does work. If you've used easy_install to install it instead of pip, then I'm not sure if there is an easy way to uninstall (someone else might know though).
Ah.. Save this file ( raw.github.com/pypa/pip/master/contrib/get-pip.py ) as c:\get-pip.py and then run python c:\get-pip.py to install pip.
More advice on installing pip on windows found here: stackoverflow.com/questions/4750806/…
i install pip when i am using this command pip install python_twitter but it give error that no such file or directory !!
He used setup.py install to install it, see his other questions.
|

Your Answer

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