Failed building wheel for xxx/configure: error: no acceptable C compiler found in $PATH錯誤及解決辦法

Failed building wheel for subprocess32/configure: error: no acceptable C compiler found in $PATH錯誤及解決辦法

  • 前言
  • 錯誤訊息
  • 解決辦法
  • 踩坑記
  • 參考連結

前言

這是筆者在Ubuntu14.04下使用Python2安裝matplotlib時所出現的錯誤。
其中matplotlib有個依賴的包叫做subprocess32。
這個錯誤就是在安裝subprocess32時發生的。

錯誤訊息

Collecting subprocess32
Downloading https://files.pythonhosted.org/packages/be/2b/beeba583e9877e64db10b52a96915afc0feabf7144dcbf2a0d0ea68bf73d/subprocess32-3.5.3.tar.gz (96kB)
Building wheels for collected packages: subprocess32
Running setup.py bdist_wheel for subprocess32: started
Running setup.py bdist_wheel for subprocess32: finished with status ‘error’
Complete output from command /root/miniconda/envs/test-environment/bin/python -u -c “import setuptools, tokenize;file=’/tmp/pip-install-4EQYjW/subprocess32/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-Pg1ke8 --python-tag cp27:
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying subprocess32.py -> build/lib.linux-x86_64-2.7
running build_ext
running build_configure
checking for gcc… no
checking for cc… no
checking for cl.exe… no
configure: error: in /tmp/pip-install-4EQYjW/subprocess32': configure: error: no acceptable C compiler found in $PATH Seeconfig.log’ for more details
Traceback (most recent call last):
File “”, line 1, in
File “/tmp/pip-install-4EQYjW/subprocess32/setup.py”, line 120, in
main()
File “/tmp/pip-install-4EQYjW/subprocess32/setup.py”, line 114, in main
‘Programming Language :: Python :: Implementation :: CPython’,
File “/root/miniconda/envs/test-environment/lib/python2.7/site-packages/setuptools/init.py”, line 143, in setup
return distutils.core.setup(**attrs)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/core.py”, line 151, in setup
dist.run_commands()
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/dist.py”, line 953, in run_commands
self.run_command(cmd)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/dist.py”, line 972, in run_command
cmd_obj.run()
File “/root/miniconda/envs/test-environment/lib/python2.7/site-packages/wheel/bdist_wheel.py”, line 188, in run
self.run_command(‘build’)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/cmd.py”, line 326, in run_command
self.distribution.run_command(command)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/dist.py”, line 972, in run_command
cmd_obj.run()
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/command/build.py”, line 127, in run
self.run_command(cmd_name)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/cmd.py”, line 326, in run_command
self.distribution.run_command(command)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/dist.py”, line 972, in run_command
cmd_obj.run()
File “/tmp/pip-install-4EQYjW/subprocess32/setup.py”, line 41, in run
self.run_command(command)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/cmd.py”, line 326, in run_command
self.distribution.run_command(command)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/dist.py”, line 972, in run_command
cmd_obj.run()
File “/tmp/pip-install-4EQYjW/subprocess32/setup.py”, line 26, in run
raise RuntimeError(configure_command + ’ failed.’)
RuntimeError: sh ./configure failed.


Failed building wheel for subprocess32
Running setup.py clean for subprocess32
Failed to build subprocess32
Installing collected packages: subprocess32
Running setup.py install for subprocess32: started
Running setup.py install for subprocess32: finished with status ‘error’
Complete output from command /root/miniconda/envs/test-environment/bin/python -u -c “import setuptools, tokenize;file=’/tmp/pip-install-4EQYjW/subprocess32/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-8KJYcJ/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying subprocess32.py -> build/lib.linux-x86_64-2.7
running build_ext
running build_configure
checking for gcc… no
checking for cc… no
checking for cl.exe… no
configure: error: in /tmp/pip-install-4EQYjW/subprocess32': configure: error: no acceptable C compiler found in $PATH Seeconfig.log’ for more details
Traceback (most recent call last):
File “”, line 1, in
File “/tmp/pip-install-4EQYjW/subprocess32/setup.py”, line 120, in
main()
File “/tmp/pip-install-4EQYjW/subprocess32/setup.py”, line 114, in main
‘Programming Language :: Python :: Implementation :: CPython’,
File “/root/miniconda/envs/test-environment/lib/python2.7/site-packages/setuptools/init.py”, line 143, in setup
return distutils.core.setup(**attrs)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/core.py”, line 151, in setup
dist.run_commands()
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/dist.py”, line 953, in run_commands
self.run_command(cmd)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/dist.py”, line 972, in run_command
cmd_obj.run()
File “/root/miniconda/envs/test-environment/lib/python2.7/site-packages/setuptools/command/install.py”, line 61, in run
return orig.install.run(self)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/command/install.py”, line 563, in run
self.run_command(‘build’)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/cmd.py”, line 326, in run_command
self.distribution.run_command(command)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/dist.py”, line 972, in run_command
cmd_obj.run()
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/command/build.py”, line 127, in run
self.run_command(cmd_name)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/cmd.py”, line 326, in run_command
self.distribution.run_command(command)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/dist.py”, line 972, in run_command
cmd_obj.run()
File “/tmp/pip-install-4EQYjW/subprocess32/setup.py”, line 41, in run
self.run_command(command)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/cmd.py”, line 326, in run_command
self.distribution.run_command(command)
File “/root/miniconda/envs/test-environment/lib/python2.7/distutils/dist.py”, line 972, in run_command
cmd_obj.run()
File “/tmp/pip-install-4EQYjW/subprocess32/setup.py”, line 26, in run
raise RuntimeError(configure_command + ’ failed.’)
RuntimeError: sh ./configure failed.


Command “/root/miniconda/envs/test-environment/bin/python -u -c “import setuptools, tokenize;file=’/tmp/pip-install-4EQYjW/subprocess32/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-8KJYcJ/install-record.txt --single-version-externally-managed --compile” failed with error code 1 in /tmp/pip-install-4EQYjW/subprocess32/
The command ‘/bin/sh -c /$HOME/miniconda/envs/test-environment/bin/pip install subprocess32’ returned a non-zero code: 1

解決辦法

看到這麼長的錯誤訊息,連要找出關鍵字都有困難,一開始用:

Command “/root/miniconda/envs/test-environment/bin/python -u -c “import setuptools, tokenize;file=’/tmp/pip-install-4EQYjW/subprocess32/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-8KJYcJ/install-record.txt --single-version-externally-managed --compile” failed with error code 1 in /tmp/pip-install-4EQYjW/subprocess32/

或:

The command ‘/bin/sh -c /$HOME/miniconda/envs/test-environment/bin/pip install subprocess32’ returned a non-zero code: 1

或:

Failed building wheel for subprocess32

這幾個關鍵字搜在網上都找不到有用的解決辦法。

後來仔細讀了錯誤訊息,才發現第一次出現error的地方是:

configure: error: in `/tmp/pip-install-4EQYjW/subprocess32’:
configure: error: no acceptable C compiler found in $PATH

這個錯誤訊息看起來有價值多了。

用這行錯誤訊息拿去網上搜,終於找到no acceptable C compiler found in $PATH when installing python這個問答。

vahid abdi的回答說明了在建構subprocess32這個包時需要有gcc, cc, cl.exe這幾個編譯器其中之一。
但是在環境中卻找不到(configure: error上面三行):

checking for gcc… no
checking for cc… no
checking for cl.exe… no

因此我們要做的就是安裝gcc這個編譯器,使用以下指令:

apt-get install -y build-essential

之後就可以成功安裝matplotlib。

踩坑記

以下是筆者試過但無效的方法:

  • 安裝python-subprocess32
apt-get -y update && apt-get -y upgrade && apt-get install -y python-subprocess32

Reading package lists…
Building dependency tree…
Reading state information…
E: Unable to locate package python-subprocess32
The command ‘/bin/sh -c apt-get install -y python-subprocess32’ returned a non-zero code: 100

不知道為什麼使用了apt-get updateapt-get upgrade之後還會找不到這個包。

  • 安裝software-properties-common
apt-get install -y software-properties-common
  • 升級pip後再次安裝
pip install --upgrade --force --ignore-installed pip

參考連結

no acceptable C compiler found in $PATH when installing python
Python 2.7 substitute subprocess with subprocess32 [closed]
document that subprocess32 wheels require --pre flag
“Unable to locate package” while trying to install packages with APT
Python 2.7, PIP: “Failed building wheel for …”中Basil Jose的回答給出了安裝常用依賴項的指令

你可能感兴趣的:(Python學習筆記,Linux,linux,python,gcc)