python 找不到模块 speech_recognition
python can't find module 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 (most recent call last): File "C:\python
projects\test.py", line 1, in
import speech_recognition as sr ModuleNotFoundError: No module named 'speech_recognition'
我还测试了它:"python -m speech_recognition"
而且效果很好。
库安装在:Python36\Lib\site-packages\speech_recognition
当你写python test.py
或
时它有效吗
pathToYourPython36Executable/python.exe test.py
进入你的命令行?
如果是这样,您使用的 IDLE 版本可能与您安装模块的位置不同。
尝试安装 SpeechRecognition
而不是 speech_recognition
:
python3 -m SpeechRecognition
你自己的 alexa?呵呵。
在 mac bigsur OS 上,这些都不适合我
sudo pip3 install --upgrade speechrecognition
sudo 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']
检查 pkg 在哪里:
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/
所以我安装了 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 (most recent call last): File "C:\python projects\test.py", line 1, in import speech_recognition as sr ModuleNotFoundError: No module named 'speech_recognition'
我还测试了它:"python -m speech_recognition" 而且效果很好。
库安装在:Python36\Lib\site-packages\speech_recognition
当你写python test.py
或
pathToYourPython36Executable/python.exe test.py
进入你的命令行?
如果是这样,您使用的 IDLE 版本可能与您安装模块的位置不同。
尝试安装 SpeechRecognition
而不是 speech_recognition
:
python3 -m SpeechRecognition
你自己的 alexa?呵呵。 在 mac bigsur OS 上,这些都不适合我 sudo pip3 install --upgrade speechrecognition sudo 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']
检查 pkg 在哪里:
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/