Ubuntu16.04 pip3 install PyAudio 出错:error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1

error message

Collecting pyaudio
  Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Building wheels for collected packages: pyaudio
  Running setup.py bdist_wheel for pyaudio ... error
  Complete output from command /usr/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-kg54s8cx/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-nwzkkq3_ --python-tag cp35:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.5
  copying src/pyaudio.py -> build/lib.linux-x86_64-3.5
  running build_ext
  building '_portaudio' extension
  creating build/temp.linux-x86_64-3.5
  creating build/temp.linux-x86_64-3.5/src
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.5/src/_portaudiomodule.o
  src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  
  ----------------------------------------
  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
    Complete output from command /usr/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-kg54s8cx/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-1k4o92s5/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    copying src/pyaudio.py -> build/lib.linux-x86_64-3.5
    running build_ext
    building '_portaudio' extension
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/src
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.5/src/_portaudiomodule.o
    src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-kg54s8cx/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-1k4o92s5/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-kg54s8cx/pyaudio/

Execute the following command:

root@robot:/home/liu# sudo apt-get install portaudio19-dev python-all-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-all-dev is already the newest version (2.7.12-1~16.04).
python-all-dev set to manually installed.
The following packages were automatically installed and are no longer required:
  fonts-lato libruby2.3 linux-headers-4.10.0-28
  linux-headers-4.10.0-28-generic linux-headers-4.13.0-36
  linux-headers-4.13.0-36-generic linux-headers-4.13.0-38
  linux-headers-4.13.0-38-generic linux-headers-4.4.0-124
  linux-headers-4.4.0-124-generic linux-image-4.10.0-28-generic
  linux-image-4.13.0-36-generic linux-image-4.13.0-38-generic
  linux-image-extra-4.10.0-28-generic linux-image-extra-4.13.0-36-generic
  linux-image-extra-4.13.0-38-generic rake ruby ruby-did-you-mean
  ruby-minitest ruby-net-telnet ruby-power-assert ruby-test-unit ruby2.3
  rubygems-integration
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libjack-dev libjack0 libportaudiocpp0
Suggested packages:
  jackd1 portaudio19-doc
The following packages will be REMOVED:
  libjack-jackd2-0
The following NEW packages will be installed:
  libjack-dev libjack0 libportaudiocpp0 portaudio19-dev
0 upgraded, 4 newly installed, 1 to remove and 546 not upgraded.
Need to get 359 kB of archives.
After this operation, 2,512 kB of additional disk space will be used.
Do you want to continue?[Y/n] y
Get:1 http://mirrors.sohu.com/ubuntu xenial/universe amd64 libjack0 amd64 1:0.124.1+20140122git5013bed0-3build2 [43.1 kB]
Get:2 http://mirrors.sohu.com/ubuntu xenial/universe amd64 libjack-dev amd64 1:0.124.1+20140122git5013bed0-3build2 [199 kB]
Get:3 http://mirrors.sohu.com/ubuntu xenial/main amd64 libportaudiocpp0 amd64 19+svn20140130-1build1 [15.4 kB]
Get:4 http://mirrors.sohu.com/ubuntu xenial/main amd64 portaudio19-dev amd64 19+svn20140130-1build1 [102 kB]
Fetched 359 kB in 2s (177 kB/s)           
dpkg: libjack-jackd2-0:amd64: dependency problems, but removing anyway as you requested:
 simplescreenrecorder depends on libjack-jackd2-0 (>= 1.9.5~dfsg-14) | libjack-0.116; however:
  Package libjack-jackd2-0:amd64 is to be removed.
  Package libjack-0.116 is not installed.
  Package libjack-jackd2-0:amd64 which provides libjack-0.116 is to be removed.
 gstreamer1.0-plugins-good:amd64 depends on libjack-jackd2-0 (>= 1.9.5~dfsg-14) | libjack-0.116; however:
  Package libjack-jackd2-0:amd64 is to be removed.
  Package libjack-0.116 is not installed.
  Package libjack-jackd2-0:amd64 which provides libjack-0.116 is to be removed.
 libavdevice-ffmpeg56:amd64 depends on libjack-jackd2-0 (>= 1.9.5~dfsg-14) | libjack-0.116; however:
  Package libjack-jackd2-0:amd64 is to be removed.
  Package libjack-0.116 is not installed.
  Package libjack-jackd2-0:amd64 which provides libjack-0.116 is to be removed.
 libasound2-plugins:amd64 depends on libjack-jackd2-0 (>= 1.9.5~dfsg-14) | libjack-0.116; however:
  Package libjack-ja
(Reading database ... 494197 files and directories currently installed.)
Removing libjack-jackd2-0:amd64 (1.9.10+20150825git1ed50c92~dfsg-1ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Selecting previously unselected package libjack0:amd64.
(Reading database ... 494188 files and directories currently installed.)
Preparing to unpack .../libjack0_1%3a0.124.1+20140122git5013bed0-3build2_amd64.deb ...
Unpacking libjack0:amd64 (1:0.124.1+20140122git5013bed0-3build2) ...
Selecting previously unselected package libjack-dev.
Preparing to unpack .../libjack-dev_1%3a0.124.1+20140122git5013bed0-3build2_amd64.deb ...
Unpacking libjack-dev (1:0.124.1+20140122git5013bed0-3build2) ...
Selecting previously unselected package libportaudiocpp0:amd64.
Preparing to unpack .../libportaudiocpp0_19+svn20140130-1build1_amd64.deb ...
Unpacking libportaudiocpp0:amd64 (19+svn20140130-1build1) ...
Selecting previously unselected package portaudio19-dev.
Preparing to unpack .../portaudio19-dev_19+svn20140130-1build1_amd64.deb ...
Unpacking portaudio19-dev (19+svn20140130-1build1) ...
Processing triggers for doc-base (0.10.7) ...
Processing 1 added doc-base file...
Setting up libjack0:amd64 (1:0.124.1+20140122git5013bed0-3build2) ...
Setting up libjack-dev (1:0.124.1+20140122git5013bed0-3build2) ...
Setting up libportaudiocpp0:amd64 (19+svn20140130-1build1) ...
Setting up portaudio19-dev (19+svn20140130-1build1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...

execute pip3 install PyAudio

again

root@robot:/home/liu# pip3 install pyaudio
Collecting pyaudio
  Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Building wheels for collected packages: pyaudio
  Running setup.py bdist_wheel for pyaudio ... done
  Stored in directory: /root/.cache/pip/wheels/f4/a8/a4/292214166c2917890f85b2f72a8e5f13e1ffa527c4200dcede
Successfully built pyaudio
Installing collected packages: pyaudio
Successfully installed pyaudio-0.2.11

Read More: