首页 > 解决方案 > ModuleNotFoundError:没有名为“六”的模块,六已安装

问题描述

我正在尝试在我的 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,所以看起来问题不存在。我已经尝试卸载和重新安装六个,以及pip install --ignore-installed sixand python -m pip install sixand 虽然两者都运行没有问题,但都没有解决我的问题。我不知道还有什么可以尝试的,有人可以帮我解决这个问题吗?

标签: pythonpipsix

解决方案


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


推荐阅读