ImportError:没有名为“tweepy.streaming”的模块; “tweepy”不是一个包

2024-03-18

我在 PyCharm ed 4 中编写了这个 tweepy 源代码。

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'])

但是,我从程序中收到了此消息。

 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

我不知道我的执行有什么问题。 请帮我。


在查看了几个答案并亲自尝试之后......

确保:

  • 您的脚本未命名为 tweepy.py

  • Tweepy是通过pip安装的

  • 尝试通过以下方式导入 OAuthHandler

    from tweepy import OAuthHandler

  • 您在尝试其他解决方案后删除了 .pyc 文件(这是我失败的地方)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ImportError:没有名为“tweepy.streaming”的模块; “tweepy”不是一个包 的相关文章

随机推荐