我正在尝试在 Pycharm 中安装 PyAudio 包,但未安装并显示此错误:
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
已经尝试过在 Pycharm 上,在 Windows 10 上运行
命令输出:
Collecting PyAudio
Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Installing collected packages: PyAudio
Running setup.py install for PyAudio: started
Running setup.py install for PyAudio: finished with status 'error'
Complete output from command C:\Users\iamsu\PycharmProjects\Casper\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\iamsu\\AppData\\Local\\Temp\\pycharm-packaging\\PyAudio\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\iamsu\AppData\Local\Temp\pip-record-lvejcfmx\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\iamsu\PycharmProjects\Casper\venv\include\site\python3.7\PyAudio:
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.7
copying src\pyaudio.py -> build\lib.win-amd64-3.7
warning: build_py: byte-compiling is disabled, skipping.
running build_ext
building '_portaudio' extension
creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release
creating build\temp.win-amd64-3.7\Release\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMS_WIN64=1 -IC:\Users\iamsu\PycharmProjects\Casper\venv\include -IC:\Users\iamsu\AppData\Local\Programs\Python\Python37\include -IC:\Users\iamsu\AppData\Local\Programs\Python\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcsrc/_portaudiomodule.c /Fobuild\temp.win-amd64-3.7\Release\src/_portaudiomodule.obj
_portaudiomodule.c
c:\users\iamsu\appdata\local\programs\python\python37\include\pyconfig.h(117): warning C4005: 'MS_WIN64': macro redefinition
c:\users\iamsu\appdata\local\programs\python\python37\include\pyconfig.h(117): note: command-line arguments: 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 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
----------------------------------------
Command "C:\Users\iamsu\PycharmProjects\Casper\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\iamsu\\AppData\\Local\\Temp\\pycharm-packaging\\PyAudio\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\iamsu\AppData\Local\Temp\pip-record-lvejcfmx\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\iamsu\PycharmProjects\Casper\venv\include\site\python3.7\PyAudio" failed with error code 1 in C:\Users\iamsu\AppData\Local\Temp\pycharm-packaging\PyAudio\
我有同样的问题,通过执行以下命令解决了。
pip install pipwin
pipwin install pyaudio
您需要安装 C++ Build Tools 才能下载此包。或者,您可以下载并安装 Visual Studio。
PyCharm 中的问题可能是因为您没有使用正确的 Python 解释器引起的。大多数用户首先安装 Python,然后安装 PyCharm,而不知道 PyCharm 会同时安装另一个 Python 安装。这应该是与您相同的问题,因为您的 PyCharm 尝试使用 Visual Studio 目录中的 build.py。所以这是您必须检查的内容:
**(也许你的问题已经解决了。我的回答可能会对面临同样问题的新手有所帮助) PyAudio 依赖于 PortAudio,它可能未安装在您的系统上。您可以尝试先手动安装 PortAudio,然后再安装 PyAudio。 如果您在 Windows 10 64 位上使用 Python 3.9,请下载名为 PyAudio‑0.2.11‑cp39‑cp39‑win_amd64.whl 的文件并使用以下命令安装它:
pip install PyAudio-0.2.11-cp39-cp39-win_amd64.whl