CentOS 6.10 下源码安装Python 3.7.2

环境:

CentOS release 6.10 (Final)

2.6.32-754.9.1.el6.x86_64

Python源码下载 : https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz

安装前准备

# 解决 import bz2 报错
yum install  bzip2-devel

# 解决 import curses 报错
yum install  ncurses-devel

# 解决 import sqlite3 报错
yum install sqlite-devel

# 解决 _dbm _gdbm 缺失提醒
yum install gdbm-devel

# 解决 _lzma 缺失提醒
yum install xz-devel

# 解决 _tkinter 缺失提醒
yum install tk-devel

# 解决 readline 缺失提醒及方向键行为非预期的问题
yum install readline-devel

yum -y install wget gcc gcc-c++ make zlib  zlib-devel readline-devel  bzip2-devel ncurses-devel sqlite-devel pyliblzma libuuid-devel
yum -y install gdbm-devel xz-devel tk-devel openssl-devel

#源码安装openssl,解决python3.7需要的openssl版本最低为1.0.2 解决:libffi libffi-develtkinter tcl-devel db4-devel libpcap-devel xz-devel gdbm-devel
yum -y groupinstall "Development tools"
tcl-develImportError: No module named _ssl
cd /opt
wget
https://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar xf openssl-1.1.1a.tar.gz
cd openssl-1.1.1a/
./config --prefix=/opt/openssl shared zlib
make && make install
vi /etc/ld.so.conf

分享图片

  ldconfig

 

安装

cd /opt

wget https://www.python.org/ftp/python/3.7.2/python-3.7.2.tgz

tar xf python-3.7.2.tgz

cd python-3.7.2

sed -i s/^#readline/readline/ Modules/Setup.dist
sed -ri s/^#(_ssl)/\1/p Modules/Setup.dist 
sed -ri s/^#([\t]-DUSE)/\1/p Modules/Setup.dist 
sed -ri s/^#([\t]-L\$(SSL))/\1/p Modules/Setup.dist

./configure --prefix=/opt/python3 --with-openssl=/opt/openssl --enable-shared --enable-optimizations

make

make install

 

ln -s /opt/python3/bin/python3 /bin/

ln -s /opt/python3/bin/pip3 /bin/

 

参考:

https://blog.51cto.com/13575683/2114585

https://www.jianshu.com/p/9b8ffb22687a

https://www.jianshu.com/p/3ec24f563b81

等等。。。

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native