ImportError: No module named 'tweepy.streaming'; 'tweepy' is not a package

拥有回忆 提交于 2019-12-11 00:00:02

问题


I wrote this tweepy sourcecode in PyCharm ed 4.

from __future__ import absolute_import, print_function
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

consumer_key="***"
consumer_secret="***"
access_token="***"
access_token_secret="***"

class StdOutListener(StreamListener):
    def on_data(self, data):
         print(data)
         return True

    def on_error(self, status):
         print(status)
if __name__ == '__main__':
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    stream = Stream(auth, l)
    stream.filter(track=['basketball'])

However, I got this message from program.

 Traceback (most recent call last):
 File "<frozen importlib._bootstrap>", line 2195, in _find_and_load_unlocked
 AttributeError: 'module' object has no attribute '__path__'

 During handling of the above exception, another exception occurred:

 file:***,in lin3, in module
 from tweepy.streaming import StreamListener
 file:***, in line 3, in module
 from tweepy.streaming import StreamListener

 ImportError: No module named 'tweepy.streaming'; 'tweepy' is not a package

I don't know what's wrong with my execution. Please help me.


回答1:


your file name should not be tweepy.py. if it is, then it will import itself.




回答2:


After reviewing several answers and trying them out myself...

Make sure that:

  • Your script is not named tweepy.py
  • Tweepy is installed through pip
  • Try to import OAuthHandler by doing

    from tweepy import OAuthHandler

  • You delete your .pyc files after trying another solution (this is where I was failing)



来源:https://stackoverflow.com/questions/33182561/importerror-no-module-named-tweepy-streaming-tweepy-is-not-a-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!