在python项目中找不到的模块?

时间:2018-06-09 13:04:06

标签: python pycharm tweepy

我在Pycharm有一个python项目。代码如下所示:

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from kafka import SimpleProducer, KafkaClient

access_token = "56078905-nIhiZaeN6pe2GeNvppxItmO6ap6YYXKXfqqAjqt8f"
access_token_secret =  "2ZD1RENb7jvXgR7TmDu6pKcgliCC3du89jG7hTibfeTI6"
consumer_key =  "e8vFKglSgPeMFueUXX4e2bglB"
consumer_secret =  "O85aPvR1u42NLinbjRbbmAb0ajN6gTVZXB4uGXfhASBdTda7jv"

class StdOutListener(StreamListener):
    def on_data(self, data):
        producer.send_messages("trump", data.encode('utf-8'))
        print (data)
        return True
    def on_error(self, status):
        print (status)

kafka = KafkaClient("localhost:9092")
producer = SimpleProducer(kafka)
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(track="trump")

但是,当我运行此操作时,我收到以下错误:

Traceback (most recent call last):
  File "/Users/nke09/kafkatest/twitterkafka.py", line 3, in <module>
    from tweepy.streaming import StreamListener
  File "/usr/local/lib/python3.6/site-packages/tweepy/__init__.py", line 12, in <module>
    from tweepy.models import Status, User, DirectMessage, Friendship, SavedSearch, SearchResults, ModelFactory, Category
  File "/usr/local/lib/python3.6/site-packages/tweepy/models.py", line 7, in <module>
    from tweepy.utils import parse_datetime, parse_html_value, parse_a_href
  File "/usr/local/lib/python3.6/site-packages/tweepy/utils.py", line 9, in <module>
    import six
ModuleNotFoundError: No module named 'six'

我不明白,因为我确实安装了六个。

3 个答案:

答案 0 :(得分:0)

您的案例中的问题是,您可能为此特定项目选择了virtual env,而不是选择现有的解释器。所以,转到Settings-->Project Interpreter,然后从选项中选择现有的python解释器。但是,我认为在执行此操作之前,您应首先执行pip install six并检查其是否已安装

答案 1 :(得分:0)

来自pycharm,

转到settings - &gt; project Interpreter

检查是否安装了six。如果已安装,您可以在表格中看到。如果没有安装,

单击右上角的+按钮,您将看到可用包的弹出窗口。然后搜索six python包。

然后点击Install package安装软件包

答案 2 :(得分:0)

也许你应该检查你的模块6是为python2还是python3安装的 使用Pip3 for python3 使用pip for python2 也许它会帮助你