redhat/centos5.x安装python3.6

本文详细介绍了在RedHat Enterprise Linux Server release 5.10环境下,如何更新软件源至清华源,安装并更新依赖,包括gcc、python-setuptools等,以及如何从源码编译安装OpenSSL 1.0.2q和Python 3.6.1,并解决安装过程中遇到的问题,如ssl和crypto模块的缺失,gcc版本问题,以及python3的链接配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

操作系统:Red Hat Enterprise Linux Server release 5.10

更新软件源

将源更新为清华源,详情参见:https://mirrors.tuna.tsinghua.edu.cn/help/centos/


安装、更新依赖

yum install -y gcc gcc44 zlib-devel python-setuptools readline-devel wget make perl

更新openssl 

# 下载并配置安装
wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2q.tar.gz
tar zxvf openssl-*
cd openssl-*
./config -fpic shared && make && make install

# 安装完成后替换掉旧ssl,旧版本为0.9.8,在python3中无法正常加载、使用
# 旧版本备份;创建新1.0.2版本的链接
mv /usr/bin/openssl /usr/bin/openssl.old
ln -s /usr/local/ssl/bin/openssl  /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl  /usr/include/openssl

# 将ssl链接库写入配置文件,ldconfig命令使之生效
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
ldconfig

注:openssl版本这里还选择1.0.x,使用过1.1.x安装失败因perl版本太低。rh5.x版本的perl最高为5.8.8,1.1.x版本最低perl版本需求为5.10.x 。对于perl的升级直接凌乱,折腾一下午决定不做,尽量少动其他依赖版本。因后续应用层还需要对perl有依赖,担心环境再不统一那就完蛋。


安装python

python使用3.6.1

官网下载、解压Python

修改其中文件:Python/Modules/Setup.dist ,大概在205行,去掉下面几行注释

# Socket module helper for socket(2)
_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

注:先记一下,后续的make altinstall后会报个警告,说_decimal模块安装失败,为了避免这个错误,需要使用gcc44进行编译安装,之前已安装了gcc44的依赖,此处安装前配置变量:

export CC=/usr/bin/gcc44

进入Python源码目录,配置、安装:

./configure --prefix=/opt/python3 --enable-shared
make  altinstall

安装过程中会报错,忘记截图,后续再装时我注意截一下。大概意思为:Error: cannot found module  lssl  ;Error: cannot found module  lcrypto  即找不到ssl模块、找不到crypto模块。创建新安装的openssl模块的软链接即可:

ln -s /usr/local/ssl/lib/libssl.so /usr/local/lib64/libssl.so
ln -s /usr/local/ssl/lib/libcrypto.so /usr/local/lib64/libcrypto.so

再执行python的make altinstall ,安装成功。

最后创建python3的软链接:

ln -s /opt/python3/bin/python3.6 /usr/local/bin/python3
ln -s /opt/python3/bin/pip3.6 /usr/local/bin/pip3 

终端敲一下python3,即进入python shell ,引入ssl不报错,即安装成功。也可使用pip3 install reqeusts尝试看看有没有问题,不报错即成功。


更新pip3 ,更新为清华源:

pip3 install pip -U
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

引用链接:

How to Enable OpenSSL 1.0.2.a (TLSv1.1 & TLSv1.2) on CentOS 5 & RHEL5

Compiling python 3.6 for centos 5.11 with openssl

对应OpenSSL脆弱性,升级OpenSSL版本至1.0.1u

 

[root@0404 ~]# pip3 install pyinstaller WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Collecting pyinstaller Using cached https://files.pythonhosted.org/packages/b0/e6/e5760666896739115b0e4538a42cdd895215581618ec885ad043dd35ee57/pyinstaller-4.10.tar.gz Requirement already satisfied: setuptools in /usr/lib/python3.6/site-packages (from pyinstaller) Requirement already satisfied: altgraph in ./.local/lib/python3.6/site-packages (from pyinstaller) Requirement already satisfied: pyinstaller-hooks-contrib>=2020.6 in ./.local/lib/python3.6/site-packages (from pyinstaller) Requirement already satisfied: importlib-metadata in ./.local/lib/python3.6/site-packages (from pyinstaller) Requirement already satisfied: zipp>=0.5 in ./.local/lib/python3.6/site-packages (from importlib-metadata->pyinstaller) Requirement already satisfied: typing-extensions>=3.6.4; python_version < "3.8" in ./.local/lib/python3.6/site-packages (from importlib-metadata->pyinstaller) Building wheels for collected packages: pyinstaller Running setup.py bdist_wheel for pyinstaller ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__=&#39;/tmp/pip-build-9i8u5dao/pyinstaller/setup.py&#39;;f=getattr(tokenize, &#39;open&#39;, open)(__file__);code=f.read().replace(&#39;\r\n&#39;, &#39;\n&#39;);f.close();exec(compile(code, __file__, &#39;exec&#39;))" bdist_wheel -d /tmp/tmpmvsymh1kpip-wheel- --python-tag cp36: running bdist_wheel running build running build_bootloader No precompiled bootloader found or compile forced. Trying to compile the bootloader for you ... Setting top to : /tmp/pip-build-9i8u5dao/pyinstaller/bootloader Setting out to : /tmp/pip-build-9i8u5dao/pyinstaller/bootloader/build Python Version : 3.6.8 (default, Nov 14 2023, 16:29:52) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] Checking for &#39;gcc&#39; (C compiler) : /usr/bin
最新发布
03-22
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值