Python2编译

本文档详细介绍了如何在Linux环境下手动下载、编译Python2,将其安装到指定目录,并在编译过程中添加SSL模块支持。在遇到错误时,通过安装e2fsprogs-devel解决,最后安装pip。整个过程适合于旧系统中需要自定义安装Python2的情况。
摘要由CSDN通过智能技术生成

下载文件

直接去官网下载tar.gz的安装包即可,这里下载的是Python-2.7.18.tgz

编译

在root目录新建software文件夹,将压缩文件放进去,新建app目录用于存放编译后的文件

解压

tar -zxvf Python-2.7.18.tgz

安装到指定目录

进入到解压后的文件,安装到/root/app/python2

./configure --prefix=/root/app/python2/

增加ssl模块的支持

上面执行之后,会生成一个Modules文件夹,修改配置文件

vi Modules/Setup

找到ssl配置地方,将注释放开

# 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
改为
# 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 && make install

错误

/usr/include/krb5.h:2606:24: et/com_err.h: No such file or directory

对于系统老的版本,可能会出现报错,需要安装e2fsprogs-devel

安装e2fsprogs-devel

yum install e2fsprogs-devel

再继续make && make install
编译成功之后,我们进入到/root/app/python2/bin目录下,会发现没有pip,因为默认python2是不自带的,需要安装

安装pip

./python -m ensurepip --default-pip

到此python的编译就成功了

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值