CentOs安装Python 3.8 出现cross compile、zlib错误 - 必(避)坑指南
CentOs (更新)安装 Python 3.8 出现的各类坑:
注:以下讨论均在 Python-3.8.12 文件夹下执行。
-
cd 进入解压后的 Python-3.8.12 文件夹后,执行 ./configure 命令出现以下错误:
If you meant to cross compile, use '--host'. See config.log' for more details
花了非常多时间搜索可能的问题,当前已有的主要解决方案都是围绕 gcc 的讨论,但我已经安装并更新到最新的 gcc 版本,因此排除 gcc 问题;
分析 config.log 日志文件,进一步发现以下问题描述:
compilation terminated. configure:3873: $? = 1 configure:3893: checking whether the C compiler works configure:3915: gcc conftest.c >&5 configure:3919: $? = 0 configure:3967: result: yes configure:3970: checking for C compiler default output file name configure:3972: result: a.out configure:3978: checking for suffix of executables configure:3985: gcc -o conftest conftest.c >&5 configure:3989: $? = 0 configure:4011: result: configure:4033: checking whether we are cross compiling configure:4041: gcc -o conftest conftest.c >&5 conftest.c:11:10: fatal error: stdio.h: No such file or directory #include <stdio.h> ^~~~~~~~~
stackoverflow 查找 stdio.h: No such file or directory 问题,猜测可能缺失 libc-dev 库,进一步查找 Centos 相对于的库,发现解决方案,执行以下命令:
yum install glibc -y
顺利解决第一坑 ./configure 问题
-
make && make install 出现 zipimport.ZipImportError: can’t decompress data 错误:
第一反应安装 zlib 相关依赖包:
yum -y install zlib*
根据搜索得到的解决方案,修改 Modules 路径下的 Setup 文件,
cd Modules vim Setup
去掉以下代码注释:
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz # 去掉注释 zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
返回 Python-3.8.12 文件夹主目录,重新执行 make && make install 命令.
注:执行以上步骤可能部分网友可以解决问题,但我按照以上步骤执行进一步报如下错误 fatal error zlib.h No such file or directory , 继续填坑!
根据参考方案1 - 仅需参考zlib安装部分,参考方案2从 zlib 官网下载源码,重新编译安装,
cd /usr/local/src wget http://zlib.net/zlib-1.2.12.tar.gz tar -zxvf zlib-1.2.12.tar.gz cd zlib-1.2.12/ ./configure make test make install
构建共享库
make clean ./configure --shared make test make install cp zutil.h /usr/local/include cp zutil.c /usr/local/include
重新回到 Python-3.8.12 文件夹,make && make install,解决问题!
反思:
- 这个问题搞了好久,从 ./configure 报错开始,就一顿乱搜,安装各种网上解决方案所要求的各类包,但都没能解决。事实上,自己也注意到了报错提示中指出的建议,即 config.log 分析,但自己光顾找别人现成的答案(“病急乱投医”),而忽视了源于自己系统的特定问题,因此浪费了很多时间!最后还是得老老实实从自身寻找原因,进而解决问题!