ModuleNotFoundError: 没有名为 'six' 的模块,已经安装了 6

时间:2021-03-28 21:26:45

标签: python pip six

我正在尝试在我的 Mac 上运行这个非常简单的文本转语音程序:

# Import the required module for text 
# to speech conversion
from gtts import gTTS
  
# This module is imported so that we can 
# play the converted audio
import os
  
# The text that you want to convert to audio
mytext = 'Welcome to geeksforgeeks!'
  
# Language in which you want to convert
language = 'en'
  
# Passing the text and language to the engine, 
# here we have marked slow=False. Which tells 
# the module that the converted audio should 
# have a high speed
myobj = gTTS(text=mytext, lang=language, slow=False)
  
# Saving the converted audio in a mp3 file named
# welcome 
myobj.save("welcome.mp3")
  
# Playing the converted file
os.system("mpg321 welcome.mp3")

但是当我尝试运行它时出现此错误:

Traceback (most recent call last):
  File "/Users/name/Documents/University/Intro to Python/Random/texttospeech.py", line 3, in <module>
    from gtts import gTTS
  File "/Users/name/Documents/University/Intro to Python/Random/gtts/__init__.py", line 3, in <module>
    from .tts import gTTS, gTTSError
  File "/Users/name/Documents/University/Intro to Python/Random/gtts/tts.py", line 6, in <module>
    from six.moves import urllib
ModuleNotFoundError: No module named 'six'

它似乎在 tts.py 中指的第 6 行是“from Six.moves import urllib”,如果这很重要的话。运行 pip show six 看起来不错,版本 1.15.0 安装在 python3.7/site-packages 中,我也在使用 IDLE 版本 3.7,所以似乎问题不存在。我尝试卸载并重新安装 6 个,以及 pip install --ignore-installed sixpython -m pip install six,虽然两者都没有问题,但都没有解决我的问题。我不知道还能尝试什么,有人能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

你在使用 virtualenv 吗?您可以尝试运行 pip -V 以查看您使用的是正确的 pip 吗? 一个常见的错误是认为由于python的默认环境变量指向某个版本,因此pip也是如此。如果您不在 virtualenv 下工作,这可能是问题所在。我建议添加更多关于您的问题的信息,因为它可能源于多种原因