Linux

How to Resolve Configure: Error: no acceptable C compiler found in $PATH

Python Installation

Tried to install python 3.7.1 in Linux and met this error: “configure: error: no acceptable C compiler found in $PATH”. No doubt, this error will also appear in Ubuntu and CentOS.

First of all, I downloaded the source from python official site, and then extract it.

[root@test python]# curl -O https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.7M  100 21.7M    0     0   850k      0  0:00:26  0:00:26 --:--:--  959k
[root@test python]# tar -zxf Python-3.7.1.tgz
[root@test python]# cd *
[root@test Python-3.7.1]# mkdir mypython

Now we start to configure it to a predefined destination.

[root@test Python-3.7.1]# ./configure --prefix=$HOME/python/mypython
...
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/root/python/Python-3.7.1':
configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details

no acceptable C compiler found in $PATH

This configuration error seemed to be related to missing or found no acceptable C compilers in $PATH. Since we are using a minimal version of Linux, it doesn’t have gcc (GNU Compiler Collection) package installed, which is a proper and suitable C compiler for make.

And what is $PATH? PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.

Since the installer found no C compiler in $PATH, a string that puts conventional binary directories together, such as /usr/bin, /usr/local/bin or /sbin, etc. to compile the source, it threw “Configure: Error: no acceptable C compiler found in $PATH” to alert users to fix the problem.

So next, I install the proper C compiler gcc by the following command and then it will appear in $PATH afterwards:

[root@test ~]# yum -y install gcc
...

In fact, there’s a better way to pass all dependency issue like “no acceptable C compiler found in $PATH” during whole installation. That is to say, you may need all essential development tools including all kinds of supportive and acceptable compilers.

[root@test ~]# yum -y groupinstall "Development Tools"
...

Now we can try it again and finish the rest of the installation.

[root@test Python-3.7.1]# ./configure --prefix=$HOME/python/mypython
...
[root@test Python-3.7.1]# make
...
[root@test Python-3.7.1]# make test
...
[root@test Python-3.7.1]# make install
...
ModuleNotFoundError: No module named '_ctypes'
make: *** [install] Error 1

There came a message that complained about “No module named ‘_ctypes'”. Now we have a library dependency problem.

libffi-devel is Required

Even if the configuration is done well and C compiler is now acceptable in $PATH, we found another issue about C compiler interface occurred during make install. In addition to C compiler, we need libffi-devel package to act as the foreign function interface for C compiler to provide ctypes and rest modules.

[root@test Python-3.7.1]# yum -y install libffi-devel
...

Let’s do it again. This time, make install found an acceptable C compiler in $PATH and worked well.

[root@test Python-3.7.1]# make install
...
Looking in links: /tmp/tmp8b7ksh64
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1

I don’t see “Configure: Error: no acceptable C compiler found in $PATH”. Do you?

GeoIP Installation via PECL

Same error “no acceptable C compiler found in $PATH” occurred when installing geoip via PECL utility.

[root@test ~]# pecl install geoip-1.1.1
...
checking for cc... no
checking for gcc... no
configure: error: in `/var/tmp/pear-build-rootS2pmRo/geoip-1.1.1':
configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details
ERROR: `/var/tmp/geoip/configure --with-php-config=/usr/bin/php-config' failed

Although PECL is not a C compiler, it’s a utility that can assist PHP packages to be installed. During the package installation, PECL need C compiler to make source. Eventually, it cannot find any C compiler in conventional $PATH.

no acceptable C compiler found in $PATH

Same error occurred again. So I installed development tools, a package group just like the above solution in python installation.

[root@test ~]# yum -y groupinstall "Development Tools"
...

Let’s try again.

[root@test ~]# pecl install geoip-1.1.1
downloading geoip-1.1.1.tgz ...
Starting to download geoip-1.1.1.tgz (13,004 bytes)
...
checking for geoip files in default path... not found
configure: error: Please reinstall the geoip distribution
ERROR: `/var/tmp/geoip/configure --with-php-config=/usr/bin/php-config' failed

It still failed, but it’s not about “no acceptable C compiler found in $PATH”. It’s about geoip-1.1.1.

geoip-1.1.1 is Required

No such “Configure: Error: no acceptable C compiler found in $PATH” this time. But we have another error which told us to install a proper package called geoip-devel first.

[root@test ~]# yum -y install geoip-devel
...

Then I tried to make it right again.

[root@test ~]# pecl install geoip-1.1.1
downloading geoip-1.1.1.tgz ...
Starting to download geoip-1.1.1.tgz (13,004 bytes)
...
Build process completed successfully
Installing '/usr/lib64/php/modules/geoip.so'
install ok: channel://pecl.php.net/geoip-1.1.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=geoip.so" to php.ini

This time, we’re good.

As for Debian or its variants, you can run the equivalent command: sudo aptitude install build-essential
to solve the configuration error.

In conclusion, the lesson I learned from this error “no acceptable C compiler found in $PATH” is that we should know and install all dependencies of configuration packages before installing python and geoip. In this case, we need an acceptable C compiler found in $PATH in order to make install all kinds of sources.

Leave a Reply

Your email address will not be published. Required fields are marked *