首先安装相关依赖包:
yum install gcc libffi-devel zlib* openssl-devel libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
tar -zxvf Python-3.7.4.tgz
–prefix:指定安装位置。
–with-ssl:ssl模块,pip3需要用到。(如果不加找不到该模块)
cd Python-3.7.4
./configure --prefix=/usr/local/python3 --with-ssl
make
make install
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
python3
如下所示,证明安装成功:
Python 3.7.0 (default, Jan 9 2019, 10:18:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
可能碰到的问题如下
报错:Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
原因:python3.7需要的openssl的版本为1.0.2或者1.1.x,经过查看centos6.8默认版本为openssl-1.0.1,如下查看
[root@centos6 sqy]# rpm -qa|grep ssl
openssl-devel-1.0.1e-58.el6_10.x86_64
openssl-1.0.1e-58.el6_10.x86_64
解决:升级openssl然后重新编译python3.7
升级参考链接升级openssl