解决 python 错误 Configure: Error: No Acceptable C Compiler Found in $PATH
当你安装一个包或应用程序时,有几个依赖项可以运行这样的包。 这些依赖项为包的某些(或全部)部分提供支持。
通常,其中一些依赖项会捆绑在一起或在安装过程中下载。 其他时候,它应该存在于您的系统中。
对于 Linux,一个重要的例子是安装 Python 时。 C 编译器是它需要的重要依赖项。
好吧,那是因为 Python 是用 C 编写的。但是,我们可能没有 C 编译器,Python 开发人员希望它出现在您的 Linux PC 上。
本文将向您展示在安装 Python 或任何需要 C 编译器的包时如何解决错误消息 configure: error: no acceptable C compiler found in $PATH 。
安装 gcc 解决 configure: error: no acceptable C compiler found in $PATH
GNU Compiler Collection (GCC) 是一个编译器,包含从 C 和 C++ 到 Go 的不同编程语言的编译器。 除了这些编译器之外,它还拥有在其支持的编程语言上运行的重要库。
从描述中,我们知道它包含在我们的 $PATH 中找不到的 C 编译器。 因此,如果您看到此错误消息 configure: error: no acceptable C compiler found in $PATH,gcc 编译器可以帮助您解决。
让我们通过在我们的 Ubuntu PC 上安装 Python 来创建相同的错误消息场景。 要安装 Python,我们需要下载 tgz 文件,这是一个使用 GNU zip (gzip) 软件保存 Python 包的压缩归档文件。
要下载 Python tgz 文件,我们可以使用 wget 命令。
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz
上面命令的输出如下,Python-3.10.6.tgz 文件存在于我们在上面命令中执行的工作目录中。
Resolving www.python.org (www.python.org)... 151.101.16.223, 2a04:4e42:4::223
Connecting to www.python.org (www.python.org)|151.101.16.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25986768 (25M) [application/octet-stream]
Saving to: ‘Python-3.10.6.tgz'
Python-3.10.6.tgz 100%[=================================================>] 24.78M 6.16MB/s in 4.9s
2022-08-15 11:54:25 (5.10 MB/s) - ‘Python-3.10.6.tgz' saved [25986768/25986768]
您可以使用 ls 命令来检查我们下载的文件。 之后,我们可以使用以下命令提取 Python-3.10.6.tgz 文件。
$ tar -zxvf Python-3.10.6.tgz
下面是代码输出和一个提取的目录 Python-3.10.6。
Python-3.10.6/
Python-3.10.6/Mac/
Python-3.10.6/Mac/README.rst
Python-3.10.6/Mac/Icons/
Python-3.10.6/Mac/Icons/PythonLauncher.icns
Python-3.10.6/Mac/Icons/IDLE.icns
Python-3.10.6/Mac/Icons/PythonCompiled.icns
Python-3.10.6/Mac/Icons/ReadMe.txt
...
现在,让我们进入目录。
$ cd Python-3.10.6
然后,使用下面的命令创建一个隐藏目录。
$ mkdir ~/.localpython
现在,让我们配置 Python $PATH 以允许我们在任何地方访问 Python。
./configure --prefix=/home/lazycruise/.localpython
这是弹出错误消息的地方。
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.10... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/home/lazycruise/Python-3.10.6':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
您可以在倒数第二行看到错误消息,configure: error: no acceptable C compiler found in $PATH。
正如我们之前所说,gcc 编译器包含我们需要的 C 编译器,以便我们成功安装 Python。 所以,让我们使用下面的命令安装 gcc 编译器。
$ sudo apt-get install build-essential
上面的命令安装了一个元包,它不安装任何东西,但提供了指向作为依赖项安装的其他几个包的链接。 对于 build-essential,它会安装编译用 C 和 C++ 编写的基本软件所需的一切。
其中包括我们需要的编译器,gcc、g++、libc6-dev、make 和 dpkg-dev。 我们可以使用所有这些包在 Ubuntu 上编写和运行 C 和 C++ 软件。
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-10-base gcc-9
gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils
libc-dev-bin libc6 libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libfakeroot
libfile-fcntllock-perl libgcc-9-dev libgcc-s1 libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0
libstdc++-9-dev libstdc++6 libtsan0 libubsan1 linux-libc-dev make manpages-dev
对于其他发行版或基础版本,命令会有所不同。
-
CentOS, Red Hat
sudo yum groupinstall "Development Tools"
-
openSUSE
zypper install --type pattern devel_basis
-
Alpine
apk add build-base
我们可以通过完整的命令执行来重复我们的配置命令。
./configure --prefix=/home/lazycruise/.localpython
现在,它成功了。 之后,我们执行下面的命令,从提取到当前工作目录的源代码构建 Python 程序和文件。
make
最后,我们执行这个命令来安装 Python 程序。
$ sudo make install
因此,要解决 configure: error: no acceptable C compiler found in $PATH 错误消息,您需要做的就是安装 gcc,它在 Ubuntu 或类似发行版上带有 meta-package、build-essentials。
相关文章
Pandas DataFrame DataFrame.shift() 函数
发布时间:2024/04/24 浏览次数:133 分类:Python
-
DataFrame.shift() 函数是将 DataFrame 的索引按指定的周期数进行移位。
Python pandas.pivot_table() 函数
发布时间:2024/04/24 浏览次数:82 分类:Python
-
Python Pandas pivot_table()函数通过对数据进行汇总,避免了数据的重复。
Pandas read_csv()函数
发布时间:2024/04/24 浏览次数:254 分类:Python
-
Pandas read_csv()函数将指定的逗号分隔值(csv)文件读取到 DataFrame 中。
Pandas 多列合并
发布时间:2024/04/24 浏览次数:628 分类:Python
-
本教程介绍了如何在 Pandas 中使用 DataFrame.merge()方法合并两个 DataFrames。
Pandas loc vs iloc
发布时间:2024/04/24 浏览次数:837 分类:Python
-
本教程介绍了如何使用 Python 中的 loc 和 iloc 从 Pandas DataFrame 中过滤数据。
在 Python 中将 Pandas 系列的日期时间转换为字符串
发布时间:2024/04/24 浏览次数:894 分类:Python
-
了解如何在 Python 中将 Pandas 系列日期时间转换为字符串