2

I have visited many forums, tried diffrent methods like brew, pip, port and many more but still am facing the same error.

View this Image for more detail

src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
    #include "portaudio.h"
             ^~~~~~~~~~~~~
    1 error generated.
    error: command '/usr/bin/gcc' failed with exit code 1

Can anyone help?

Vishal Kumar
  • 23
  • 1
  • 3

3 Answers3

12

For me it was:

brew install portaudio
python -m pip install --global-option='build_ext' --global-option='-I/opt/homebrew/Cellar/portaudio/19.7.0/include' --global-option='-L/opt/homebrew/Cellar/portaudio/19.7.0/lib' pyaudio
FRV
  • 691
  • 5
  • 4
4

This Solution is tested on M1 Macs[Please do check with other].

After the installation of HomeBrew on your system, perform the installation of PortAudio. Next follow the steps mentioned below:

Use the command to install PortAudio

sudo brew install portaudio

After successful installation of PortAudio, enter the following command.

sudo nano $HOME/.pydistutils.cfg

Next, enter the following lines in the opened window

[build_ext]
include_dirs=/Users/<enter-your-system-username>/homebrew/Cellar/portaudio/19.20140130/include/
include_dirs=/Users/<enter-your-system-username>/homebrew/Cellar/portaudio/19.20140130/lib/

Note: PortAudio location may be different for you and also don't forget to replace your PC username.

Finally run the command

pip install pyaudio

or

pip3 install pyaudio

vkshah
  • 56
  • 3
  • 2
    This solution worked for me, but at first I was getting this error: `pydistutils.cfg' [line 3]: option 'include_dirs' in section 'build_ext' already exists`. After the first `include_dirs`, I added a new section `build_ext_1` for the second `include_dirs` and it worked. – Shend Nov 04 '21 at 08:45
  • @shend What was the lines you wrote? I'm not sure I understand but same error as you. – DoPeT Mar 30 '22 at 00:31
0

vkshah has an error in his second line. It should ready library_dirs instead of include_dirs:

include_dirs=/Users/<enter-your-system-username>/homebrew/Cellar/portaudio/19.20140130/include/
library_dirs=/Users/<enter-your-system-username>/homebrew/Cellar/portaudio/19.20140130/lib/```
MSP
  • 21
  • 2
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31594722) – Arnie97 Apr 27 '22 at 16:35
  • It does "provide answers that don't require a clarification from the asker", namely that the answer given by vkshah had a typo that would have made it incorrect. On top of the code snippets, I gave an explanation that was pretty darned clear (library_dirs instead of include_dirs). So, would you rather have the vkshah's original answer stand (which I am very thankful for, as I was completely stuck, and this got me 95% there), or have the correct answer that would actually solve users' problems? – MSP May 20 '22 at 19:27
  • Hi, I'm sorry for the words above. I didn't expect that my choice in the moderator review queue would trigger some rude automatic bot reply like that. I fully agree and appreciate your errata about vkshah's answer. However, I would suggest to use the "edit" or "improve this answer" link under vkshah's answer instead, which is more friendly to future readers. After the community volunteers accept your improvements, you will be credited in the original answer as an editor, and this separate answer entry could be deleted then. – Arnie97 May 30 '22 at 09:13