centos7源码编译python3.12.3

centos7源码编译python3.12.3
{
1 下载
https://www.python.org/downloads/source/
选择最新的stable
2 解压
tar zxvf Python-3.12.3.tgz
3 配置
./configure --enable-optimizations
4 编译
make -j 8
出现错误:SystemError: <built-in function compile> returned NULL without setting an exception
解决:转centos源码编译高版本gcc
5 清理
make clean
6 重新配置
./configure --enable-optimizations
7 出现错误提示:configure: error: C compiler cannot create executables
解决问题的过程
{
  问题1:为什么新gcc不能创建可执行文件?
  写了一个打印helloworld的c文件,使用gcc编译
  出现错误提示:gcc: 致命错误:cannot execute ‘cc1’: execvp: 没有那个文件或目录
  问题2:cc1为什么找不到?
  查询cc1在哪
  [root@coco Downloads]# find / -name cc1
  /opt/gcc-13.2.0/libexec/gcc/x86_64-pc-linux-gnu/13.2.0/cc1
  查询gcc在哪
  [root@coco Downloads]# find / -name gcc
  /opt/gcc-13.2.0/libexec/gcc
  /opt/gcc-13.2.0/lib/gcc
  /opt/gcc-13.2.0/bin/gcc
  使用/opt/gcc-13.2.0/bin/gcc编译可以成功,但是使用复制过去的/usr/bin/gcc不能编译成功
  问题3:为什么复制过去的/usr/bin/gcc找不到cc1,而原目录里的gcc能找到cc1。
  卸载老版本的gcc
  yum remove gcc
  使用vim打开/etc/bashrc,在末尾加上export PATH="$PATH:/opt/gcc-13.2.0/bin"
  刷新/etc/bashrc
  source /etc/bashrc
  再次验证gcc
  成功编译helloworld。
  回答问题3:可能gcc是根据相对目录寻找cc1,这个是配置编译的时候决定的。如果是绝对目录寻找,反而不合理。
  为什么修改环境变量,相比把所有的文件都拷贝或移动到/urs目录,修改环境变量改动更小,只需加一行。复制文件会将系统变脏,后面难以恢复。
  回答问题2:因为gcc是按相对目录寻找cc1
  回答问题1:因为仅仅将高版本gcc复制到/usr/bin是不够的,它还需要它所依赖的环境才能正常工作
}
8 再次配置
./configure --enable-optimizations
9 再次编译
make -j 8
10 安装
make install

出现错误提示:raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/home/bibo/Downloads/Python-3.12.3/python', '-W', 'ignore::DeprecationWarning', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/tmp/tmpt5apmxib/pip-24.0-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmpt5apmxib\', \'--root\', \'/\', \'--upgrade\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
make: *** [install] 错误 1
解决问题的过程
{
  问题1:为什么make install会出错?
  执行make altinstall,出现同样的问题提示。
  向上看,有其它问题提示:zipimport.ZipImportError: can't decompress data; zlib not available
  问题2:是不是因为zlib没有安装,这里的zlib是指zlib库吗,可以用yum安装吗?
  使用yum安装zlib
  [root@coco Python-3.12.3]# yum install zlib
  已加载插件:fastestmirror, langpacks
  Loading mirror speeds from cached hostfile
   * base: mirrors.aliyun.com
   * extras: mirrors.aliyun.com
   * updates: mirrors.aliyun.com
  软件包 zlib-1.2.7-21.el7_9.x86_64 已安装并且是最新版本
  无须任何处理?
  提示已安装
  问题3:是不是需要python依赖的zlib,python依赖的zlib怎样安装?
  安装zlib开发包
  yum install zlib-devel
  重新make
  make clean
  make -j 8
  问题4:make altinstall与make install的实际区别,实现原理?
  问题5:使用yum remove pyhon后为什么移python还在?
  出现同样的错误提示:ModuleNotFoundError: No module named 'zlib'
  重新配置编译,出现提示:Could not build the ssl module!
  虽然出现了新的问题,但是zlib的问题没有了。
  回答问题5:因为yum本身依赖python。执行yum remove python它是提示日志:错误:尝试移除受保护的 "yum"
  回答问题4:因为yum本事是依赖python的,并且是python2,现在安装python3,如果直接make install会把python2覆盖,导致yum出问题。make altinstall只不过是将文件命名为python3。
  回答问题3:直接yum install zlib-devel即可。就是普通的zlib开发包。python本身就是依赖c库的。
  回答问题2:可以用yum安装。
  回答问题1:因为缺少zlib。
}

  Python requires a OpenSSL 1.1.1 or newer
尝试解决此问题
{
  1 转centos7源码编译openssl1.1.1w,本文最后
  问题1:怎样源码编译openssl新版后,编译python时在新版与旧版共存时使用这个新版openssl?
  make clean
  ./configure --enable-optimizations
  make -j 8
  日志提示:Could not build the ssl module!
                   Python requires a OpenSSL 1.1.1 or newer
  问题2:Openssl已经安装好,怎样让他被别人找到?
  ./configure --help
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
查询openssl在哪
find / -name openssl
/usr/local/bin/openssl
/usr/local/include/openssl
/usr/lib64/openssl/engines

./configure --enable-optimizations --libdir=/usr/lib64/openssl/engines --includedir=/usr/local/include/openssl
make -j 8
  日志提示:[ERROR] _hashlib failed to import: libcrypto.so.1.1: cannot open shared object file: No such file or directory
此时python已经找到openssl了,到此这个问题结束。
  回答问题2:使用--includedir告诉python openssl的头文件opensllv.h在哪即可。
  回答问题1:配置python时使用参数--includedir指定新版openssl的头文件在哪。
}

日志提示:[ERROR] _hashlib failed to import: libcrypto.so.1.1: cannot open shared object file: No such file or directory
尝试解决此问题
{
[ERROR] _ssl failed to import: libssl.so.1.1: cannot open shared object file: No such file or directory
/usr/local/lib64/
make clean
./configure --enable-optimizations --libdir=/usr/local/lib64/ --includedir=/usr/local/include/openssl
make -j 8
  日志提示:[ERROR] _hashlib failed to import: libcrypto.so.1.1: cannot open shared object file: No such file or directory
说明告诉python libssl.so.1.1在哪依然无法导入。
[root@coco Python-3.12.3]# find / -name libcrypto.so.1.1
/usr/local/lib64/libcrypto.so.1.1
  问题1:怎样才能找到/usr/local/lib64/libcrypto.so.1.1
[root@coco Python-3.12.3]# openssl version
openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
说明是openssl自己找不到依赖的动态库
[root@coco Python-3.12.3]# find / -name openssl
/usr/local/bin/openssl
[root@coco Python-3.12.3]# ldd /usr/local/bin/openssl
    linux-vdso.so.1 =>  (0x00007ffdd4946000)
    libssl.so.1.1 => not found
    libcrypto.so.1.1 => not found
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f0e17c92000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f0e17a76000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f0e176a8000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f0e17e96000)
[root@coco Python-3.12.3]# ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
[root@coco Python-3.12.3]# ldd /usr/local/bin/openssl
    linux-vdso.so.1 =>  (0x00007ffe3a329000)
    libssl.so.1.1 => not found
    libcrypto.so.1.1 => /lib64/libcrypto.so.1.1 (0x00007f4e8dddc000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f4e8dbd8000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4e8d9bc000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f4e8d5ee000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f4e8e2c1000)
[root@coco Python-3.12.3]# ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
[root@coco Python-3.12.3]# openssl version
OpenSSL 1.1.1w  11 Sep 2023
make -j 8
  回答问题1:在openssl默认搜索动态库的目录里创建自己找不到的依赖的动态库的软链接。
./configure --enable-optimizations --includedir=/usr/local/include/openssl
make -j 8
  说明不需要指定库目录在哪。
  仅包含openssl的头文件所在目录即可找到它,不需要包含openssl的库目录。
}

日志提示:The following modules are *disabled* in configure script:
_sqlite3                                                       

The necessary bits to build these optional modules were not found:
_bz2                  _ctypes               _ctypes_test       
_curses               _curses_panel         _lzma              
_tkinter              _uuid                 readline           
To find the necessary bits, look in configure.ac and config.log.

Checked 111 modules (31 built-in, 69 shared, 1 n/a on linux-x86_64, 1 disabled, 9 missing, 0 failed on import)
make[1]: 离开目录“/home/bibo/Downloads/Python-3.12.3”
尝试解决此问题
{
安装_bz2
yum install bzip2-devel
安装_ctypes
yum install libffi-devel
安装_ctypes_test
yum install python3-devel(暂时不装,因为正在源码编译)
安装_curses
yum install ncurses-devel
安装_curses_panel
yum install ncurses-devel
安装_lzma
yum install xz-devel
安装 _tkinter
yum install tk-devel
安装 _uuid
yum install libuuid-devel(已安装)
安装 readline
yum install readline-devel
清理
make clean
配置
./configure --enable-optimizations --includedir=/usr/local/include/openssl
日志提示:checking for stdlib extension module _tkinter... missing
问题1:为什么安装了tk-devel,依然找不到_tkinter?重启后也找不到?
编译
make -j 8
日志提示:
The necessary bits to build these optional modules were not found:
_tkinter                                                       
To find the necessary bits, look in configure.ac and config.log.

Checked 111 modules (31 built-in, 77 shared, 1 n/a on linux-x86_64, 1 disabled, 1 missing, 0 failed on import)
make[1]: 离开目录“/home/bibo/Downloads/Python-3.12.3”
yum -y install tkinter
./configure --enable-optimizations --includedir=/usr/local/include/openssl
日志提示:checking for stdlib extension module _tkinter... missing
日志提示:Package libb2 was not found in the pkg-config search path.
 --libdir=DIR            object code libraries [EPREFIX/lib]
yum install python3-tkinter.x86_64
日志提示:checking for stdlib extension module _tkinter... missing
make -j 8
make altinstall
[root@coco Python-3.12.3]# echo $?
0
这次成功了,说明thinter找不到的问题可以忽略。
./configure --enable-optimizations --includedir=/usr/local/include/openssl --with-tcltk-includes="-I/usr/include" --with-tcltk-libs="-L/usr/lib64 -ltcl8.5 -ltk8.5"
日志提示:checking for stdlib extension module _tkinter... missing
--with-tcltk-includes, --with-tcltk-libs
回答问题1:不知道,放弃了。也许是它本身就不支持。
}
}

centos7源码编译openssl1.1.1w
{
1 下载
https://www.openssl.org/source/old/1.1.1/index.html
2 解压
tar zxvf openssl-1.1.1w.tar.gz
3 配置编译测试安装
./config
make
make test
{
出现错误日志:    /usr/bin/perl .././test/run_tests.pl  )
../test/recipes/01-test_abort.t .................... Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
查看文档NOTES.PERL: - on Linux distributions based on RPMs, you will need to install
   'perl-core' rather than just 'perl'.
centos安装perl-core
安装
yum install perl-core.x86_64
}
make install
}

  • 18
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值