I have been trying to get PyAudio to install in my virtual environment but have failed to get it to load.
When I try to install it through Pip (linux mint) I get the following:
Collecting pyaudio
Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Building wheels for collected packages: pyaudio
Building wheel for pyaudio (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/doug/Documents/HiFiWave/venv/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yGZpB4/pyaudio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yGZpB4/pyaudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-t3OMsn --python-tag cp27
cwd: /tmp/pip-install-yGZpB4/pyaudio/
Complete output (16 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying src/pyaudio.py -> build/lib.linux-x86_64-2.7
running build_ext
building '_portaudio' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-5Z483E/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
src/_portaudiomodule.c:28:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for pyaudio
Running setup.py clean for pyaudio
Failed to build pyaudio
Installing collected packages: pyaudio
Running setup.py install for pyaudio ... error
ERROR: Command errored out with exit status 1:
command: /home/doug/Documents/HiFiWave/venv/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yGZpB4/pyaudio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yGZpB4/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 /tmp/pip-record-oTUpfe/install-record.txt --single-version-externally-managed --compile --install-headers /home/doug/Documents/HiFiWave/venv/include/site/python2.7/pyaudio
cwd: /tmp/pip-install-yGZpB4/pyaudio/
Complete output (16 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying src/pyaudio.py -> build/lib.linux-x86_64-2.7
running build_ext
building '_portaudio' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-5Z483E/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
src/_portaudiomodule.c:28:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /home/doug/Documents/HiFiWave/venv/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yGZpB4/pyaudio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yGZpB4/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 /tmp/pip-record-oTUpfe/install-record.txt --single-version-externally-managed --compile --install-headers /home/doug/Documents/HiFiWave/venv/include/site/python2.7/pyaudio Check the logs for full command output.
I searched Stack Overflow and came upon a handful of similar questions but none of them seemed to work. For example, I found the following solution here.
pip install -e git+http://people.csail.mit.edu/hubert/git/pyaudio.git#egg=pyaudio
It produces the following failure in terminal:
Obtaining pyaudio from git+http://people.csail.mit.edu/hubert/git/pyaudio.git#egg=pyaudio
Cloning http://people.csail.mit.edu/hubert/git/pyaudio.git to ./venv/src/pyaudio
Running command git clone -q http://people.csail.mit.edu/hubert/git/pyaudio.git /home/doug/Documents/HiFiWave/venv/src/pyaudio
Installing collected packages: pyaudio
Running setup.py develop for pyaudio
ERROR: Command errored out with exit status 1:
command: /home/doug/Documents/HiFiWave/venv/bin/python2 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/doug/Documents/HiFiWave/venv/src/pyaudio/setup.py'"'"'; __file__='"'"'/home/doug/Documents/HiFiWave/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
cwd: /home/doug/Documents/HiFiWave/venv/src/pyaudio/
Complete output (19 lines):
running develop
running egg_info
writing src/PyAudio.egg-info/PKG-INFO
writing top-level names to src/PyAudio.egg-info/top_level.txt
writing dependency_links to src/PyAudio.egg-info/dependency_links.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
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-5Z483E/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
src/_portaudiomodule.c:28:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /home/doug/Documents/HiFiWave/venv/bin/python2 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/doug/Documents/HiFiWave/venv/src/pyaudio/setup.py'"'"'; __file__='"'"'/home/doug/Documents/HiFiWave/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 Check the logs for full command output.
The following installs correctly:
sudo apt-get install python-pyaudio python3-pyaudio
When I attempt to import it into the file (whetehr in VSCode or PyCharm) it fails to load.
import pyaudio
I get the same with import Pyaudio and import pyaudio
Am I installing this completely wrong and, if so, how can I go about accomplishing it correctly? Additionally, since the last method installed correctly in my virtualenv, am I importing it incorrectly into my code?
Thank you all for your time and if there is anything I can add for clarity, please don't hesitate to ask.