Python教程

Python2编译

本文主要是介绍Python2编译,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Python2编译

    • 下载文件
    • 编译
      • 解压
      • 安装到指定目录
      • 增加ssl模块的支持
      • 编译安装
      • 错误
      • 安装e2fsprogs-devel
    • 安装pip

下载文件

直接去官网下载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的编译就成功了

这篇关于Python2编译的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!