python无法找到模块speech_recognition

时间:2018-04-11 12:34:59

标签: python speech-recognition

所以我安装了speech_recognition库,但是当我尝试导入它时,它说它无法找到它。这是我正在使用的代码。

import speech_recognition as sr

r = sr.Recognizer()
with sr.Microphone() as source:
    audio = r.listen(source)

try:
    print("You said: " + r.recognize(audio))
except:
    print("i didn't quite get that")

但是当我运行它时会显示出来。

  

Traceback(最近一次调用最后一次):File" C:\ python   projects \ test.py",第1行,in       将speech_recognition导入为sr ModuleNotFoundError:没有名为' speech_recognition'

的模块

我还测试了它:" python -m speech_recognition" 它运作得很好。

库安装在:Python36 \ Lib \ site-packages \ speech_recognition

3 个答案:

答案 0 :(得分:0)

python test.py

时是否有效

pathToYourPython36Executable/python.exe test.py进入命令行?

如果是这样,您可能正在使用与安装模块的位置不同的IDLE版本。

答案 1 :(得分:0)

尝试安装SpeechRecognition而不是speech_recognition

python3 -m SpeechRecognition

答案 2 :(得分:0)

你自己的alexa?呵呵。 在 mac bigsur OS 上,这些都不适合我 sudo pip3 install --upgrade 语音识别 须藤 pip3 安装语音识别 pip3 安装语音识别

我修复了我的系统检查我安装 pkg 的位置的问题

python3 --version
Python 3.8.2

检查路径:

python3 -c "import sys; print(sys.path)"
['', '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python38.zip', '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8', '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/lib-dynload', '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages']

检查包在哪里:

python3 -m SpeechRecognition
/Applications/Xcode.app/Contents/Developer/usr/bin/python3: No module named SpeechRecognition

使用 pop install 我明白了,不同的路径

sudo pip3 install --upgrade speechrecognition
Requirement already satisfied: speechrecognition in /Users/paul/Library/Python/3.7/lib/python/site-packages (3.8.1)

所以我手动将 pkgs 复制到我需要的路径:

sudo -H pip3 install --upgrade speechrecognition
Requirement already satisfied: speechrecognition in /Library/Python/3.7/site-packages (3.8.1)
paul@MacBook-Air-de-Paul git % ls -lstr /Library/Python/3.7/site-packages
total 0
0 drwxr-xr-x    9 root  wheel   288 Jan 30 00:12 Pillow-8.1.0.dist-info
0 drwxr-xr-x  103 root  wheel  3296 Jan 30 00:12 PIL
0 drwxr-xr-x    9 root  wheel   288 Jan 30 00:15 pip-21.0.1.dist-info
0 drwxr-xr-x    7 root  wheel   224 Jan 30 00:15 pip
0 drwxr-xr-x   10 root  wheel   320 Mar  3 11:56 speech_recognition
0 drwxr-xr-x   12 root  wheel   384 Mar  3 11:56 SpeechRecognition-3.8.1.dist-info

sudo cp -r /Library/Python/3.7/site-packages/speech_recognition /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/

sudo cp -r /Library/Python/3.7/site-packages/SpeechRecognition-3.8.1.dist-info /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/