直接去官网下载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/
上面执行之后,会生成一个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
yum install e2fsprogs-devel
再继续make && make install
编译成功之后,我们进入到/root/app/python2/bin目录下,会发现没有pip,因为默认python2是不自带的,需要安装
./python -m ensurepip --default-pip
到此python的编译就成功了