Unable to install PyAudio on M1 Mac [PortAudio already installed] - pip

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?

These steps worked on M1 Pro chips
Install portaudio
brew install portaudio
Link portaudio
brew link portaudio
Copy the path where portaudio was installed (use it in the next step)
brew --prefix portaudio
Create .pydistutils.cfg in your home directory
sudo nano $HOME/.pydistutils.cfg
then paste the following
[build_ext]
include_dirs=<PATH FROM STEP 3>/include/
library_dirs=<PATH FROM STEP 3>/lib/
Install pyaudio
pip install pyaudio
or
pip3 install pyaudio

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

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

The main challenge we're encountering here is that pyaudio doesn't know where to find the portaudio libraries since, according to the source, it only looks in these locations for darwin platform installations:
include_dirs += ['/usr/local/include', '/usr/include']
external_libraries_path += ['/usr/local/lib', '/usr/lib']
This won't do if you're using a homebrew installation of portaudio, particularly so with Apple Silicon since there isn't a pre-built wheel in PyPi. This means setuptools/pip will need to build the package from source.
There are a few ways of configuring setuptools to use additional paths, including passing arguments, using a .pydistutils.cfg file, among others, but the second option worked for me given I'm installing pyaudio to a few Python environments.
Building off of some of the answers above, you can copy the following below to install pyaudio in one go.
# Install portaudio, will print list of paths where it's been installed if already done
brew list portaudio || brew install portaudio
# Link portaudio, will print a warning if already linked
brew link portaudio
# Create a pydistutils config file with the portaudio lib paths set correctly (no copying/pasting paths required)
cat <<EOF >> .pydistutils.cfg
[build_ext]
include_dirs=`brew --prefix portaudio`/include/
library_dirs=`brew --prefix portaudio`/lib/
EOF
# install (build) package with pip
python -m pip install pyaudio
All we're doing is telling setuptools to also look for C/C++ headers where portaudio has been installed by homebrew.

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/```

For me, I am running Big Sur on an M1 Mac. I followed all the instructions mentioned in other threads to:
install portaudio
arch -arm64 brew install portaudio
start a venv
python3 -m venv env
source env/bin/activate
install pyaudio
arch -arm64 pip install --no-cache-dir --global-option='build_ext' --global-option='-I/opt/homebrew/include' --global-option='-L/opt/homebrew/lib' pyaudio==0.2.11
TIP #1
If you see error on portaudio.h file not found, the solution is specifying the pyaudio version at the end. Because it kept trying to install version '0.2.12' which failed. I specify the version of pyaudio to '0.2.11' (see above).
TIP #2
After successfully installing pyaudio, you may see error PyAudio C module _portaudio, that is due to pip built it(_portaudio.cpython-36m-darwin.so) in x86_64 architecture. It's not compatible with arm64 portaudio, in this case, make sure to include arch -arm64 in front of pip to build the correct binary.
TIP #3
Use an older version of python, I personally used version 3.6.
Oh, and make sure the single quote is actually ' if you copied the command from a text editor.
Hope this helps!

first you need to download portaudio using homebrew
brew install portaudio
Then try to install pyaudio directly
pip install pyaudio
if you are getting error while installing follow below step
Or
if you are facing any error mentioned bellow you can follow these steps
error 1
option 'include_dirs' in section 'build_ext' already exists
error 2
Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects
error 3
#include "portaudio.h"
^~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
solution start here
after installing homebrew you have to link it
brew link portaudio
in some cases it will say that it has been already linked then simply ignore
we need path of portaudio where it is exactly installed
brew --prefix portaudio
it will gives you path of portaudio
then you have to check if pydistutils.cfg file exists or not
sudo cat $HOME/.pydistutils.cfg
if file exists then it will open else create it will below command
sudo cat $HOME/.pydistutils.cfg
so in these file we have to define proper path here
[build_ext]
include_dirs=/--PATH--/include/
library_dirs=/--PATH--/lib/
you can get that path by running below command
brew --prefix portaudio
if that path is not working then try below path
[build_ext]
include_dirs=/Users/<username>/homebrew/Cellar/portaudio/19.20140130/include/
library_dirs=/Users/<username>/homebrew/Cellar/portaudio/19.20140130/lib/

If you use mac os
Install Homebrew (insert link into the terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" )
Insert command into the terminal:
brew install portaudio
Insert command into the terminal:
pip install pyaudio
p.s. sometimes you need upgrade your pip installer
These actions solved my problem (mac os Mojave 10.14.4)

Related

ERROR:Failed building wheel for h5pyFailed to build h5pyERROR:Could not build wheels for h5py,which is required toinstall pyproject.toml-basedprojects

I'm getting this error when I'm running the following command to install tensorflow.
python3 -m pip install tensorflow-macos
ERROR: Failed building wheel for h5py
Failed to build h5py
ERROR: Could not build wheels for h5py, which is required to install pyproject.toml-based projects
I tired to install this wheel manually, from the official link (https://pypi.org/project/h5py/#files), it got installed properly but I'm still getting the same error.
I'm facing the above issue in Mac Book M1 chip.
The official doc to use brew install.
$ brew install hdf5
If the above command gives you rosetta 2 issue, then run:-
arch -arm64 brew install hdf5
Once, the h5py installation is done, run following 2 commands:-
$ export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.12.0_4 OR export HDF5_DIR=/opt/homebrew/opt/hdf5 (if hdf5 is installed in the "/opt/homebrew/opt/hdf5" location, you have to check it out first)
$ pip install --no-binary=h5py h5py
Note:- in the first command "1.12.0_4" is the version of hdfc installed in my system, you have to change it according to yours.
If you are getting the aforementioned error implies you must be using poetry.
Finally run:-
poetry install
We are running the above command, In case poetry wants to update anything.
Once we run poetry install, it might update existing libraries or download new libraries.
So we have to update poetry.lock file as well.
poetry lock
After installing hdf5 try "export HDF5_DIR=/opt/homebrew/opt/hdf5"
Ref: https://github.com/h5py/h5py/issues/2035#issuecomment-1028226141
This works for me:
Install brew (https://brew.sh/)
brew install hdf5
export HDF5_DIR=$(brew --prefix hdf5) (as #sgt pepper said)
pip install --no-binary=h5py h5py

Install GTK+ >= 3.16 with PyGObject bindings on MacOS 10.15

when I'm typing the command
brew install pygobject3 --with-python#2 gtk+3
I'm always getting the error message
invalid option --with-python#2
I'm getting the same error message when I want to run the gtk+3 under mac os 10.15
Namespace Gtk not available
Maybe the Version of 10.15 of MacOS the problem....
gtk+3 version 3.24.12 and pygobject3 Version 3.34.0 are installed.
Installation of homebrew for MacOS
gtk+3 version 3.24.12 and pygobject3 Version 3.34.0 are installed.
Python3.7 is installed
File "...anaconda3/envs/python37/lib/python3.7/site-packages/gi/__init__.py", line 129, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available
I would like to run the program DemonEditor on MacOS 10.15 (Catalina)
to make some settings of my engima2 satellite receiver, for this I need the requirements "GTK+ >= 3.16 with PyGObject bindings".
Maybe some of the experts can help me.
Thanks very much
Since I am the author of this program, I am forced to report that since the program is designed for Linux, it will not work on MacOS without minor changes to the program itself. But still it’s possible.
DemonEditor
Тo resolve dependencies, it is enough to install as follows:
brew install gtk+3 pygobject3 adwaita-icon-theme
pip3 install requests
Upd.
I created an experimental brunch and added small changes to the program for the possibility of testing the launch in the MacOS. Perhaps not all the functionality will work (I have not tested it), but the program should start.
Gud luck!
STRIKE. It works, I can start the DemonEditor-GUI under 10.15. I have remove all packages via the
brew remove --force $(brew list)
installed the three packages again, via
brew install python3 gtk+3 pygobject3 adwaita-icon-theme
BUT. The most important step was to add the "Installation folder" of the brew packages to my python path but execute the comand
export PYTHONPATH=/usr/local/lib/python3.7/site-packages.
My assumption is, that due to fact, that I have installed an own conda-environment for python37, the site-packages have to be added to the path.
Big thanks for the help.
On my test system, I did not set any paths or environment variables! Just installed python 3 with the command:
brew install python3
Then I installed the dependencies as described above.Then I downloaded the archive from here, and in the unpacked folder of the program I simply gave the command:
./start.py
Below is the output of the commands python3 --version and brew list
Compare with your list, perhaps this will somehow help identify the missing components.
python3 --version
Python 3.7.4
brew list
adwaita-icon-theme libepoxy
atk libffi
cairo libpng
fontconfig librsvg
freetype libtiff
fribidi lzo
gdbm openssl#1.1
gdk-pixbuf pango
gettext pcre
glib pixman
gobject-introspection pkg-config
graphite2 py2cairo
gsettings-desktop-schemas py3cairo
gtk+3 pygobject3
harfbuzz python
hicolor-icon-theme python#2
icu4c readline
jpeg sqlite
libcroco xz
Upd. For the experiment, I removed all my packages with the command:
brew remove --force $(brew list)
Then again installed by commands as described above
brew install python3 gtk+3 pygobject3 adwaita-icon-theme
Working!

Trying to install kivy for python on mac os 10.12

so I am trying to install kivy on my mac.From their instructions page, I am on step 2, and have to enter the command $ USE_OSX_FRAMEWORKS=0 pip install kivy. However, when I put this in terminal, I get the error error: command '/usr/bin/clang' failed with exit status 1, and as a result Failed building wheel for kivy. Does anyone know how to address this issue?
Just had this issue, and was able to fix it following the directions on the kivy mac OS X install page, with one modification as follows:
$ brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer
$ pip3 install Cython==0.25.2
$ pip3 install kivy
pip3 is my reference to pip for Python 3.6 as I have two different versions of python on my system. May just be pip install for you.
Hope this helps!

Install OpenCV on Mac - VirtualEnv (Updated bash_profile and pip error)

I'm trying to install OpenCV on my Mac (OS X 10.11.3) using this tutorial because it uses a VirtualEnv, which is a way to ensure consistency in development.
I skipped Steps 1&2 since I already have Xcode and Homebrew. Step 3 worked well (after updating ~/.bash_profile as instructed):
User:~ user$ brew update
Already up-to-date.
User:~ user$ source ~/.bash_profile
User:~ user$ which python
/usr/local/bin/python
User:~ user$
The trouble is in Step 4:
User:~ user$ pip install virtualenv virtualenvwrapper
-bash: /usr/local/bin/pip: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
User:~ user$
This is probably because I'm in the local bin due to adding this to ~/.bash_profile from Step 3:
# Homebrew
export PATH=/usr/local/bin:$PATH
This basically means I can't access pip from that location, but when I try to install it locally (with the above lines added in ~/.bash_profile), it says:
User:~ user$ brew install pip
Error: No available formula with the name "pip"
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:
https://pip.readthedocs.org/en/stable/installing/#install-pip
User:~ user$
How can I access pip with my updated ~/.bash_profile from Step 3? Thanks!
Ok, I figured out the problem.
I was getting the same errors as this stackoverflow question, so I ran the recommended
brew link python
which encountered the same errors as this stackoverflow question, so I ran the recommended
brew link --overwrite python
which seemed to correct the problem and allows me to run pip while accessing Homebrew packages first.

pytables installation failed

I do:
sudo pip install --upgrade tables
I get:
/usr/bin/ld: cannot find -lhdf5
collect2: ld returned 1 exit status
.. ERROR:: Could not find a local HDF5 installation.
You may need to explicitly state where your local HDF5 headers and
library can be found by setting the ``HDF5_DIR`` environment
variable or by using the ``--hdf5`` command-line option.
Complete output from command python setup.py egg_info:
/usr/bin/ld: cannot find -lhdf5
however:
$ echo $HDF5_DIR
/opt/hdf5/
$ ls /opt/hdf5/
bin include lib share
$ ls /opt/hdf5/lib/
libhdf5.a libhdf5_hl.la libhdf5_hl.so.8 libhdf5.la libhdf5.so libhdf5.so.8.0.1
libhdf5_hl.a libhdf5_hl.so libhdf5_hl.so.8.0.1 libhdf5.settings libhdf5.so.8
What's wrong? How to debug? I already tried to set HDF5_DIR to /opt/ or to /opt/hdf5/lib.
I also had the same error on Debian sid trying to work in a local virtualenv. To work around it I did:
apt-get build-dep python-tables
HDF5_DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial/ && pip install tables
... now it's working.
I was able to fix this easily in OSX with virtual environments using the following code:
$ brew install hdf5
$ pyvenv test
$ workon myvenv # to get pytables working within the virtual environment myvenv
$ pip install numpy numexpr cython
$ pip install tables
(taken from andreabedini post in https://github.com/PyTables/PyTables/issues/385)
I'm having a similar problem, but I'm using the leading edge not the pip release (see Aside).
I also tried pointing to the library itself
export HDF5_DIR=/usr/lib/libhdf5.so.6
but it did not work.
Aside: You can try the leading edge of PyTables if you think your bug may have been addressed recently:
sudo pip install git+https://github.com/PyTables/PyTables
.
The build (that was caused by pip install...) seemed to progress further after I installed the dev version of the hdf5 library (libhdf5-openmpi-dev). The build still failed for other reasons, but it's another direction you could try.
Perhaps you can install the stable wheel file for your os for pytables from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pytables
Use this command to check for which file to download
path/to/pythonX.Y -m pip debug --verbose
And this command to install the wheel file
pip install C:/some-dir/some-file.whl
I tried everything without success. The only way I could I achieved was using nehalecky's answer I got here:
https://github.com/PyTables/PyTables/issues/219
In a nutshell, you should do these 2 commands, correcting the path, of course:
sudo python3 setup.py build_ext --inplace --hdf5=/usr/lib/x86_64-linux-gnu/hdf5/serial/
sudo python3 setup.py install --hdf5=/usr/lib/x86_64-linux-gnu/hdf5/serial/
Hope it helps!

Resources