Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

speech recognition - How to properly install PyAudio for the latest version of Python?

I was using speech_recognition with the latest version of Python (3.9). And for some reason, pip did not (still does not) allow me to install pyaudio.

sample of the error message:

_portaudiomodule.c
    c:program filespython39includepyconfig.h(117): warning C4005: 'MS_WIN64': macro redefinition
    src/_portaudiomodule.c: note: see previous definition of 'MS_WIN64'
    src/_portaudiomodule.c(29): fatal error C1083: Cannot open include file: 'portaudio.h': No such file or directory
    error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit code 2
    ----------------------------------------

It has been meaningless for me to look for what portaudio.h does. Here is the solution. I hope you don't waste your time like I did.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The reason is pip gets the packages from PyPi. And PyPi does not have PyAudio package that supports Python 3.9. This is why, it is useless to try and install pyaudio with pip install pyaudio. What you should do, instead, is you go to Unofficial Windows Binaries for Python Extension Packages page and download the pip wheel:

Unofficial Windows Binaries for Python Extension Packages

last step is to run

pip install [insert pyaudio wheel directory]pyAudio-0.2.11-cp39-cp39-win_amd64.whl

You should be alright with this.

By the way, this trick works with other packages that you want to run with the latest python version.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...