90

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

I tried 2 different ways to install 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.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Waaberi Ibrahim
  • 917
  • 1
  • 7
  • 5
  • 3
    Did you read the error message from the first command, specifically the part that says "Microsoft Visual C++ 14.0 is required."? – jwodder Sep 11 '18 at 20:37
  • I'm pretty sure you're also going to need to [install PortAudio](http://portaudio.com/docs/v19-doxydocs/tutorial_start.html). – abarnert Sep 11 '18 at 21:12
  • How to install PortAudio? – Waaberi Ibrahim Sep 11 '18 at 23:26
  • installing the vc++ lib is annoying because i have a higer version installed already. such as `Microsoft Visual C++ 2015-2022 Redistributable(x86)`. i don't want to uninstall higher version first. – Lei Yang Jan 27 '22 at 01:45
  • Related to this, I tried a `pip install pyaudio` using Python 3.10.11 and it successfully installed from a cached wheel (I'd tried this before somewhere?) but I can't seem to `import pyaudio` in VSCode. Anyone know what the library is called? – icedwater May 11 '23 at 01:18

18 Answers18

184

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

  • find your Python version by python --version mine is 3.7.3 for example
  • the easiest way to check either you have 64 or 32 Python just open it in the terminal:

  • find the appropriate .whl file 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 .whl file with pip for example in my case:
pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl
Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
  • 3
    Hi Foad, I have followed your steps and went to that folder and ran like this, C:\Users\harnish.shah\Downloads>pip3 install PyAudio-0.2.11-cp38-cp38-win_amd64.whl ERROR: PyAudio-0.2.11-cp38-cp38-win_amd64.whl is not a supported wheel on this platform. WARNING: You are using pip version 19.2.3, however version 20.0.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command. even I had tried with upgrading pip also but can't install. Can you please help with this? – Harnish Shah Jan 23 '20 at 10:18
  • 1
    @HarnishShah I don't think it has anything to do with the `pip upgrade`. I think you either don't have admin rights on your device, or you haven't followed the first two steps correctly. – Foad S. Farimani Jan 23 '20 at 12:02
  • 2
    Worked also on pycharm when I cloned the file to the project folder and then run the pip3 install – JVal aka SolidSnake Oct 13 '20 at 22:49
  • [I can't install pyaudio on Windows? How to solve “error: Microsoft Visual C++ 14.0 is required.”?](https://stackoverflow.com/a/57731053/5033247) – Smart Manoj Dec 30 '20 at 09:26
  • 2
    @HanishShalah You have to match the wheel to your platform. The file you tried is for Python 3.8 64-bit. Check your Python version as described in the answer and try again with the appropriate `.whl` file. – BoarGules Dec 30 '20 at 09:40
  • 1
    Confirmed this works on Python 3.9 Windows 10. – The Grindfather Jun 19 '21 at 19:57
161

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

pip install pipwin
pipwin install pyaudio
Zafar Faheem
  • 2,014
  • 1
  • 7
  • 7
35

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.

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>.

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

Edit. See the pipwin comment for automated way of using Mr Gohlke's libs . Note that I've not used it myself and I'm not sure about selecting different package flavors like vanilla and mkl versions of numpy.

TheEagle
  • 5,808
  • 3
  • 11
  • 39
Agalin
  • 376
  • 2
  • 5
  • [I can't install pyaudio on Windows? How to solve “error: Microsoft Visual C++ 14.0 is required.”?](https://stackoverflow.com/a/57731053/5033247) – Smart Manoj Dec 30 '20 at 09:30
17

Use Conda instead of pip. It works perfectly

conda install PyAudio
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
Par bas
  • 213
  • 2
  • 2
  • Note that (Ana)conda has a license agreement. So depending on your context, this might not be an option. – Bengt Jun 30 '21 at 11:06
10

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/

Jonas Wolff
  • 2,034
  • 1
  • 12
  • 17
9

For some reason pip does not work, instead you could try first installing "pipwin" if you don't already have it Open a cmd and paste this:

pip install pipwin

and then install PyAudio using:

pipwin install pyaudio

It should work. But if you don't want to use pipwin.. just install it and then uninstall it afterwards by simply using:

pip uninstall pipwin
Liban
  • 101
  • 1
  • 2
5

The problem is pyaudio does not have wheels for python 3.7 just try some lower version like 3.6 then install pyaudio

It works

Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
johnson
  • 379
  • 2
  • 17
4

If you have anaconda install than you just need to use command: conda install PyAudio.

In order to execute this command you must set thePYTHONPATH environment variable in anaconda.

elite gamer88
  • 73
  • 1
  • 1
  • 13
Ritik Jain
  • 143
  • 1
  • 6
4

You should install python 3.6 version because python 3.7 version doesn't 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 "

Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
  • [I can't install pyaudio on Windows? How to solve “error: Microsoft Visual C++ 14.0 is required.”?](https://stackoverflow.com/a/57731053/5033247) – Smart Manoj Dec 30 '20 at 09:30
2

Seems PyAudio is supported by Python 2.7, 3.4, 3.5, and 3.6. Refer https://people.csail.mit.edu/hubert/pyaudio/

Please suggest if there is any alternate way to install PyAudio on Python 3.8.2

Mayank Tripathi
  • 489
  • 5
  • 16
1

You should just install python 3.6. I tried it and it worked. Just install that version of python and just do the normal download process (pip install pyaudio).

cigien
  • 57,834
  • 11
  • 73
  • 112
0

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/

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

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

pip install PyAudio‑0.2.11‑cp37‑cp37m‑win_amd64.whl and it works.

susan097
  • 3,500
  • 1
  • 23
  • 30
  • [I can't install pyaudio on Windows? How to solve “error: Microsoft Visual C++ 14.0 is required.”?](https://stackoverflow.com/a/57731053/5033247) – Smart Manoj Dec 30 '20 at 09:30
0

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:

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

and it should work.

shreyash
  • 67
  • 4
0

For PyCharm use the Terminal: pip install pipwin pipwin install PyAudio <-- Remember the capital letters

Jumpstar
  • 65
  • 1
  • 7
0

Try following command for MacOS using python 3.8.2 install Homebrew on your terminal

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Visual Studio Code terminal

1.brew install portaudio

2.pip install pyaudio

0

Here's how I solved this damn problem on Linux Fedora-36.

sudo dnf install portaudio-devel 

After that, portaudio, portaudio-devel and alsa-lib-devel packages were installed.

Then Kindly;

pip install pyaudio

All the problem went away with my execution.

XTechnology
  • 89
  • 1
  • 4
  • Nice answer, but this is for Windows. Hopefully it helps someone, but otherwise this isn't directly related to the question... – icedwater May 11 '23 at 01:15
0

I assume you are building something requiring input from the user and also the keyboard. You will need various libraries, I will list all of them directly from the source...

!apt-get install -y portaudio19-dev libasound-dev libportaudio2 libportaudiocpp0
!pip install pyaudio wave keyboard pydub

It installs various dependencies for pyaudio which may hinder the installation of pyaudio.

Shay
  • 15
  • 5
  • Thank you for submitting an answer! However, it looks like your suggestion is intended for a Linux system using apt, whereas the OP is looking for help on the Windows platform. – Robert Nubel Mar 09 '23 at 16:56
  • Then replace apt-get install -y with pip install. – Shay Mar 11 '23 at 03:23
-3

I had the same issue but solved it by using 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
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135