首页 > 解决方案 > tweepy - ModuleNotFoundError

问题描述

我在 Python 中有一个脚本来使用 Tweepy 收集数据。当我运行它时,我收到了这条消息,ModuleNotFoundError: No module named 'tweepy.auth'; 'tweepy' is not a package
我已经做了一个 pip install tweepy,我的 python 版本是 3.8.0。这是我的代码的开头(写在崇高的文本上):

import tweepy
from tweepy.auth import OAuthHandler


consumer_key = "XXX"
consumer_secret = "XXX"
access_token = "XXX"
access_token_secret = "xxx"

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

我的谜底在哪里?谢谢

标签: pythonoauthmoduletweepy

解决方案


您是否尝试过不导入 OAuthHandler?你可能不需要。Tweepy 的文档建议:

import tweepy

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

推荐阅读