【问题标题】:Why can't I import PyAudio?为什么我不能导入 PyAudio?
【发布时间】:2021-04-17 15:22:16
【问题描述】:

我试图导入 PyAudio,但它一直给我一个错误。如果这是我的计算机的问题,我使用的是 Windows 64x 和 Python 3.9.4。这是错误:

ERROR: Command errored out with exit status 1:
     command: 'c:\program files\python\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\alext\\Desktop\\Olive\\venv\\src\\pyaudio\\setup.py'"'"'; __file__='"'"'C:\\Users\\alext\\Desktop\\Olive\\venv\\src\\pyaudio\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps --user --prefix=
         cwd: C:\Users\alext\Desktop\Olive\venv\src\pyaudio\
    Complete output (13 lines):
    running develop
    running egg_info
    creating src\PyAudio.egg-info
    writing src\PyAudio.egg-info\PKG-INFO
    writing dependency_links to src\PyAudio.egg-info\dependency_links.txt
    writing top-level names to src\PyAudio.egg-info\top_level.txt
    writing manifest file 'src\PyAudio.egg-info\SOURCES.txt'
    reading manifest file 'src\PyAudio.egg-info\SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'src\PyAudio.egg-info\SOURCES.txt'
    running build_ext
    building '_portaudio' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\program files\python\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\alext\\Desktop\\Olive\\venv\\src\\pyaudio\\setup.py'"'"'; __file__='"'"'C:\\Users\\alext\\Desktop\\Olive\\venv\\src\\pyaudio\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps --user --prefix= Check the logs for full command output.

如果有人知道如何解决此问题,请告诉我!我还在学习如何阅读 Python 日志/错误!谢谢!

【问题讨论】:

标签: python


【解决方案1】:

注意这一点:

error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/

看来您需要 C++ 14.0。 我不确定哪个链接会更好,但这里有一些我发现的。 https://visualstudio.microsoft.com/visual-cpp-build-tools/ https://visualstudio.microsoft.com/downloads/

【讨论】:

    【解决方案2】:

    当前 PyAudio PIP 包未预编译,请参阅预编译包列表 [此处]。对于 Python 3.9,它以源代码形式提供,直到 Python 3.6 才被编译。

    源码编译包需要安装Visual Studio,即使编译也不一定能成功,所以最好安装二进制预编译包。

    但是还有一个包的替代来源,here。下载文件PyAudio‑0.2.11‑cp39‑cp39‑win_amd64.whl并通过python -m pip install PyAudio‑0.2.11‑cp39‑cp39‑win_amd64.whl安装。这个包是预编译的,不需要 Visual Studio。

    【讨论】:

    • 我应该把文件放在哪里来安装它?我尝试将其放入我的项目中,但它一直说它不是有效文件。
    • @RaNdOm_PERsOn159 你能告诉我你的控制台输出和错误信息吗?还可以尝试使用--verbose 标志安装,它会显示更多信息,即执行pip install --verbose filename.whl。我想你下载有错误,没有完全下载,你可以尝试重新下载。还要在您的浏览器中查看它是否已完成下载,因为该站点速度很慢,下载可能需要一些时间。
    • @RaNdOm_PERsOn159 我也有 Windows x64 和 Python 3.9,并且刚刚成功安装了这个包,this is 在我的控制台中的样子。
    猜你喜欢
    • 2018-08-30
    • 2020-12-23
    • 2018-01-12
    • 2021-11-24
    • 2020-04-24
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多