【问题标题】:ImportError: No module named tweepy - In pythonImportError:没有名为 tweepy 的模块 - 在 python 中
【发布时间】:2015-05-09 21:04:16
【问题描述】:

我正在尝试使用 AWS 进行情​​绪分析,如下节所述 http://docs.aws.amazon.com/gettingstarted/latest/emr/getting-started-emr-sentiment-tutorial.html

一切都很好,直到我遇到以下错误 [ec2-user@ip-10-65-140-113 情绪]$ ls 在此处输入代码collector.py twaiter.py twaiter.pyc twitterparams.py

[ec2-user@ip-10-65-140-113 sentiment]$ **collector.py kindle**
-bash: collector.py: command not found
[ec2-user@ip-10-65-140-113 sentiment]$ python collector.py kindle
Traceback (most recent call last):
  File "collector.py", line 6, in <module>
    from twaiter import TWaiter
  File "/home/ec2-user/sentiment/twaiter.py", line 5, in <module>
    from tweepy import StreamListener
**ImportError: No module named tweepy**

关于为什么会这样的任何帮助。 twaiter.py 有以下内容。我打开 twaiter.py 看到第 5 行,就在这里

[ec2-user@ip-10-65-140-113 sentiment]$ vi twaiter.py


 1 # based on http://badhessian.org/2012/10/collecting-real-time-twitter-data-w    ith-the-streaming-api/
  2 # with modifications by http://github.com/marciw
  3 # requires Tweepy https://github.com/tweepy/tweepy
  4
  5 from tweepy import StreamListener
  6 import json, time, sys
  7
  8 class TWaiter(StreamListener):
  9
 10     # see Tweepy for more info
 11
 12     def __init__(self, api = None, label = 'default_collection'):
 13         self.api = api or API()
 14         self.counter = 0
 15         self.label = label
 16         self.output  = open(label + '.' + time.strftime('%b%d-%H%M') + '.txt    ', 'w')
 17         self.deleted  = open('deleted_tweets.txt', 'a')
 18
 19     def on_data(self, data):
 20         # The presence of 'in_reply_to_status' indicates a "normal" tweet.
@

【问题讨论】:

  • 错误说明了一切 - 无法导入 tweepy 模块。确定安装了吗?

标签: python amazon-web-services tweepy


【解决方案1】:

消息“ImportError: No module named tweepy”清楚地表明ec2机器没有安装tweepy库。因此,在运行当前的 python 脚本时,它无法找到它,因此会出现导入错误。

有几种方法可以安装 tweepy。 Linux 机器中的一种简单方法是
sudo pip install tweepy

其他方式有:

http://code.google.com/p/tweepy/

您可以通过同一个 Google 代码链接访问它的教程 wiki 页面。

要使用 easy_install 安装它,只需运行 easy_install tweepy

用 git 安装它:

git 克隆 git://github.com/joshthecoder/tweepy.git
cd tweepy
python setup.py 安装

要从源代码安装它,请从 http://pypi.python.org/pypi/tweepy 下载源代码,然后运行类似:

tar xzvf tweepy-1.7.1.tar.gz
cd tweepy-1.7.1
python setup.py 安装

详情请咨询Where and how can I install twitter's Python API?

另外,如果出现进一步的错误,请参考ImportError: No module named tweepy

【讨论】:

    猜你喜欢
    • 2018-09-02
    • 2015-02-11
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 2015-12-09
    • 2012-01-26
    • 2020-12-15
    • 2015-11-17
    相关资源
    最近更新 更多