Python 我无法在 Windows 上安装 pyaudio?如何解决“错误:需要 Microsoft Visual C++ 14.0。”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52283840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:03:53  来源:igfitidea点击:

I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."?

pythonpython-3.xwindowspyaudio

提问by Waaberi Ibrahim

I have a Windows 10 PC and I want to install pyaudio to use it with my chatbot, powered by chatterbot.

我有一台 Windows 10 PC,我想安装 pyaudio 以将它与我的聊天机器人一起使用,由 chatterbot 提供支持。

I tried 2 different ways to install pyaudio.

我尝试了 2 种不同的方式来安装 pyaudio。

The first way is doing this on the command prompt:

第一种方法是在命令提示符下执行此操作:

python -m pip install PyAudio

This is the result:

这是结果:

   C:\Users\Waaberi>python -m pip install PyAudio
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 ... error
    Complete output from command C:\Users\Waaberi\AppData\Local\Programs\Python\Python37-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\Waaberi\AppData\Local\Temp\pip-install-e5le61j0\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\Waaberi\AppData\Local\Temp\pip-record-adj3zivl\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    copying src\pyaudio.py -> build\lib.win32-3.7
    running build_ext
    building '_portaudio' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

    ----------------------------------------
Command "C:\Users\Waaberi\AppData\Local\Programs\Python\Python37-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\Waaberi\AppData\Local\Temp\pip-install-e5le61j0\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\Waaberi\AppData\Local\Temp\pip-record-adj3zivl\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Waaberi\AppData\Local\Temp\pip-install-e5le61j0\PyAudio\

The second way is entering this command:

第二种方式是输入这个命令:

python pip install python-pyaudio

and it does nothing.

它什么也不做。

回答by Foad

The answer by Agalinis already great and I just want to explain it in a step by step format for a novice like myself:

Agalin回答已经很好了,我只想为像我这样的新手一步一步地解释它:

  • find your Python version by python --versionmine is 3.7.3for example
  • the easiest way to check either you have 64 or 32 Python just open it in the terminal:
  • 例如,通过python --version我找到你的 Python 版本3.7.3
  • 检查是否有 64 个或 32 个 Python 的最简单方法只需在终端中打开它:

  • find the appropriate .whlfile from here, for example mine is PyAudio?0.2.11?cp37?cp37m?win_amd64.whl, and download it.
  • go to the folder where it is downloaded for example cd C:\Users\foobar\Downloads
  • install the .whlfile with pipfor example in my case:
  • .whl这里找到合适的文件,例如我的是PyAudio?0.2.11?cp37?cp37m?win_amd64.whl,然后下载它。
  • 例如,转到下载它的文件夹 cd C:\Users\foobar\Downloads
  • 例如在我的情况下安装.whl文件pip
pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl

回答by Zafar Faheem

First run your IDE or CMD as Administrator and run the following:

首先以管理员身份运行您的 IDE 或 CMD 并运行以下命令:

pip install pipwin
pipwin install pyaudio

回答by Agalin

There is no wheel (prebuilt package) for Python 3.7 on Windows (there is one for Python 2.7 and 3.4 up to 3.6) so you need to prepare build environment on your PC to use this package. Easier would be finding the wheel for 3.7 as some packages are quite hard to build on Windows.

Windows 上没有用于 Python 3.7 的轮子(预构建包)(Python 2.7 和 3.4 到 3.6 有一个轮子),因此您需要在 PC 上准备构建环境才能使用此包。更容易找到 3.7 的轮子,因为有些软件包很难在 Windows 上构建。

Christoph Gohlke (University of California) hosts Windows wheels for most popular packages for nearly all modern Python versions, including latest PyAudio. You can find it here: https://www.lfd.uci.edu/~gohlke/pythonlibs/(download can be quite slow). After download, just type pip install <downloaded file here>.

Christoph Gohlke(加利福尼亚大学)为几乎所有现代 Python 版本(包括最新的 PyAudio)的最流行软件包提供 Windows 轮子。你可以在这里找到它:https: //www.lfd.uci.edu/~gohlke/pythonlibs/(下载可能很慢)。下载后,输入pip install <downloaded file here>.

There is no difference between python -m pip install, and pip installas long as you're using default installation settings and single python installation. python pipactually tries to run file pipin the current directory.

只要您使用默认安装设置和单个 python 安装python -m pip install, 和之间没有区别pip installpython pip实际上尝试pip在当前目录中运行文件。

回答by Jonas Wolff

you may need to try

你可能需要尝试

pip install --upgrade setuptools

you may also need to install Visual Studio 2015, and remember to choose to install Visual C++ 14.0 https://visualstudio.microsoft.com/visual-cpp-build-tools/

您可能还需要安装 Visual Studio 2015,记得选择安装 Visual C++ 14.0 https://visualstudio.microsoft.com/visual-cpp-build-tools/

回答by Ritik Jain

If you have anaconda install than you just need to use command: conda install PyAudio. But for this to be run on command prompt you must have PYTHONPATH environment variable set of anaconda.

如果您安装了 anaconda,则只需使用命令:conda install PyAudio。但是要在命令提示符下运行它,您必须拥有 anaconda 的 PYTHONPATH 环境变量集。

回答by Vallamkonda Neelima

You should install python 3.6 version because python 3.7 version doesnot support pyaudio 1 step: Then download the .whl file
according to your python version and the configuration of your machine in your python folder which is newly installed. For me it is python 3.6 and 64 bit machine. Download the file from here (https://www.lfd.uci.edu/~gohlke/pythonlibs/) 2 step: run your cmd and type " pip install your downloaded file name here"

您应该安装python 3.6版本,因为python 3.7版本不支持pyaudio 1步骤:然后
根据您的python版本和您的机器配置在新安装的python文件夹中下载.whl文件。对我来说,它是 python 3.6 和 64 位机器。从这里下载文件 ( https://www.lfd.uci.edu/~gohlke/pythonlibs/) 2 步:运行你的 cmd 并在此处输入“pip install你下载的文件名

回答by susan097

I have got the same error as :

我遇到了与以下相同的错误:

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

错误:需要 Microsoft Visual C++ 14.0。使用“Microsoft Visual C++ 构建工具”获取它:https: //visualstudio.microsoft.com/downloads/

As, said by @Agaline, i download the outside wheel from this Christoph Gohlke.

正如@Agaline 所说,我从这个Christoph Gohlke下载了外轮

If your is Python 3.7then try to PyAudio?0.2.11?cp37?cp37m?win_amd64.whland use command as, go to the download directroy and:

如果您Python 3.7尝试PyAudio?0.2.11?cp37?cp37m?win_amd64.whl使用命令作为,请转到下载目录并:

pip install PyAudio?0.2.11?cp37?cp37m?win_amd64.whland it works.

pip install PyAudio?0.2.11?cp37?cp37m?win_amd64.whl它有效。

回答by Rudraksh Jain

I had the same issue but solved it by using Ubuntu.

我有同样的问题,但通过使用 Ubuntu 解决了它。

  1. python -m pip install pyaudio
  2. Install sudo, apt-get and then install homebrew &/ linuxbrew on your linux subsystem using Ubuntu.
  3. The latest version supports ubuntu.
  4. brew install portaudio
  5. Make sure you have python/python3 installed on the terminal
  6. Make sure the current location is added as path in your virtual computer's path in environment Variable.
  7. brew link portaudio
  1. python -m pip install pyaudio
  2. 安装 sudo、apt-get,然后使用 Ubuntu 在你的 linux 子系统上安装 homebrew 和/linuxbrew。
  3. 最新版本支持ubuntu。
  4. brew install portaudio
  5. 确保你在终端上安装了 python/python3
  6. 确保将当前位置添加为环境变量中虚拟计算机路径中的路径。
  7. brew link portaudio

回答by johnson

The problem is pyaudiodoes not support python 3.7just try some lower version like 3.5then install pyaudio

问题是pyaudio不支持 python 3.7只是尝试一些像3.5这样的低版本然后安装pyaudio

It works

有用

回答by shreyash

If you are using Python 3.7.3 and Windows 10 64-bit machine then try the following command. Go to the download folder and Install following command:

如果您使用的是 Python 3.7.3 和 Windows 10 64 位机器,请尝试以下命令。转到下载文件夹并安装以下命令:

pip install PyAudio?0.2.11?cp37?cp37m?win_amd64.whl

and it should work.

它应该工作。