E:\Eprogramfiles\Anaconda3\envs\myenvpy38>pip3 install pyaudio
Collecting pyaudio
Using cached PyAudio-0.2.11.tar.gz (37 kB)
Using legacy 'setup.py install' for pyaudio, since package 'wheel' is not installed.
Installing collected packages: pyaudio
Running setup.py install for pyaudio ... error
ERROR: Command errored out with exit status 1:
command: 'c:\python38\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Administrator\\AppData\\Local\\Temp\\pip-install-m6oeci17\\pyaudio_c8557100e30446cabb941c1c6428849d\\setup.py'"'"'; __file__='"'"'C:\\Users\\Administrator\\AppData\\Local\\Temp\\pip-install-m6oeci17\\pyaudio_c8557100e30446cabb941c1c6428849d\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Administrator\AppData\Local\Temp\pip-record-49wse8x_\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python38\Include\pyaudio'
cwd: C:\Users\Administrator\AppData\Local\Temp\pip-install-m6oeci17\pyaudio_c8557100e30446cabb941c1c6428849d\
Complete output (9 lines):
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.8
copying src\pyaudio.py -> build\lib.win-amd64-3.8
running build_ext
building '_portaudio' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\python38\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Administrator\\AppData\\Local\\Temp\\pip-install-m6oeci17\\pyaudio_c8557100e30446cabb941c1c6428849d\\setup.py'"'"'; __file__='"'"'C:\\Users\\Administrator\\AppData\\Local\\Temp\\pip-install-m6oeci17\\pyaudio_c8557100e30446cabb941c1c6428849d\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Administrator\AppData\Local\Temp\pip-record-49wse8x_\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python38\Include\pyaudio' Check the logs for full command output.
WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
You should consider upgrading via the 'c:\python38\python.exe -m pip install --upgrade pip' command.
========================================================
原因:
与是否安装了 Visual C++ 14.0 or greater 无关。
========================================================
解决方案:
直接用pip安装的pyaudio不支持3.7,所以在安装或import的时候会报错。
所以直接下载whl文件安装即可。
whl下载地址:
https://github.com/intxcc/pyaudio_portaudio/releases
切换到whl文件目录,直接用pip安装
pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl
>>> import pyaudio
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\pyaudio.py", line 116, in <module>
import _portaudio as pa
ModuleNotFoundError: No module named '_portaudio'
C:\Users\Administrator\PycharmProjects\untitled\venv\Scripts>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyaudio
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\pyaudio.py", line 116, in <module>
import _portaudio as pa
ModuleNotFoundError: No module named '_portaudio'
>>>
The official PyAudio 0.2.11 does not support Python 3.7+, and trying to install results in the error C1083: Cannot open include file: 'portaudio.h'
.
However, there are unofficial wheels for PyAudio that support 3.7+.
If you are using the official version, you must use Python 3.6 with PyAudio 0.2.11.
pip will fetch and install PyAudio wheels (prepackaged binaries). Currently, there are wheels compatible with the official distributions of Python 2.7, 3.4, 3.5, and 3.6.
http://people.csail.mit.edu/hubert/pyaudio/
————————————————
原文链接:https://blog.csdn.net/a506681571/article/details/85201279