Python ImportError:没有名为';tweepy.streaming'';tweepy';这不是一个包裹

Python ImportError:没有名为';tweepy.streaming'';tweepy';这不是一个包裹,python,tweepy,Python,Tweepy,我用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="***" acc

我用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
回溯(最近一次呼叫最后一次):
文件“”,第2195行,在“查找”和“加载”中解锁
AttributeError:“模块”对象没有属性“\u_路径”
在处理上述异常期间,发生了另一个异常:
文件:**,在lin3中,在模块中
从tweepy.streaming导入StreamListener
文件:**,第3行,模块中
从tweepy.streaming导入StreamListener
导入错误:没有名为“tweepy.streaming”的模块tweepy’不是一个包
我不知道我的死刑有什么问题。
请帮帮我。

您的文件名不应该是tweepy.py。如果是,那么它将导入自身。

在回顾了几个答案并亲自尝试之后

确保:

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

  • Tweepy通过pip安装

  • 尝试通过执行以下操作导入OAuthHandler

    从tweepy导入OAuthHandler

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


你把自己的python脚本保存为tweepy.py是什么意思?我不知道你在说什么。上面保存python代码的文件名是什么?对我来说很有用。谢谢,为我工作。谢谢