Eddie
Eddie

Reputation: 21

Installed Twitter module for python cannot be imported

$ python3 setup-py install

....

Installed /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/twitter-1.17.1-py3.5.egg
Processing dependencies for twitter==1.17.1
Finished processing dependencies for twitter==1.17.1

$ python3 twitter.py
Traceback (most recent call last):
  File "twitter.py", line 1, in <module>
    from twitter import Twitter 
  File "/Users/eddiee/2_python/twitter.py", line 1, in <module>
    from twitter import Twitter 
ImportError: cannot import name 'Twitter'

What might cause the problem:

Due to the restrictions of the preinstalled python on Mac, I installed another new python and changed the path. But I don't know how to install the module to the new python.

Upvotes: 0

Views: 225

Answers (2)

Eddie
Eddie

Reputation: 21

The problem here is I names my file as "twitter.py". When I imported the twitter module, python automatically imported the file itself, because the current file has a higher priority over the module. Simply changing the file name can solve the problem.

Upvotes: 0

David
David

Reputation: 11

Eddie:

Try to change the import line to:

    import twitter

or:

    from twitter import Twitter

Hope it helps.

Upvotes: 1

Related Questions