【问题标题】:Import "speech_recognition" could not be resolved无法解析导入“speech_recognition”
【发布时间】:2022-11-18 03:59:06
【问题描述】:

我安装了语音识别和 pyttsx3 库

pip install SpeechRecognition
pip install pyttsx3

但是当我尝试导入它们时它给出了两个错误

Import "speech_recognition" could not be resolved
Import "pyttsx3" could not be resolved

这是我的代码

import speech_recognition as sr
import pyttsx3

audio = sr.Recognizer()

【问题讨论】:

    标签: python speech-recognition pyttsx3


    【解决方案1】:

    通常发生这种情况是因为虚拟环境或解释器问题。可能的修复:

    1. 确保您在 IDE 中使用的解释器与安装库的解释器相同。

    2. 在虚拟环境的情况下与上面相同。

    3. 如果您的 IDE 是 VS Code,则打开 settings.json 文件并将 python 服务器设置为 Jedi 而不是 Microsoft/Pylance。

      我遇到了类似的问题,无法诊断出确切原因,但不知何故,流行的 CodeRunner 扩展和 VS 代码推荐的 python 扩展有冲突。因此,我禁用了前者并且程序执行没有任何问题

    【讨论】:

    • 我将解释器更改为库所在的解释器并且它起作用了,谢谢!!
    【解决方案2】:

    enter image description here

    我遇到了类似的问题,但即使使用不同的解决方案将服务器更改为 Jedi,它仍然无法识别导入 speech_recognition

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-04
    • 2013-10-04
    • 1970-01-01
    • 2016-03-12
    • 2018-08-07
    • 2012-11-06
    • 2015-08-04
    相关资源
    最近更新 更多