yum install zlib-devel bzip2-devel openssl-devel ncurses-devel -y
yum install libffi-devel -y
tar -zxvf Python-3.6.2.tgz
cd Python-3.6.2
./configure --prefix=/usr/local/python36
make && make install
如果make install之后出现如下错误,需要安装libffi-devel,重新编译安装python3:
File "/root/Python-3.7.2/Lib/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
make: *** [install] 错误 1
ModuleNotFoundError: No module named '_ssl'
支持ssl需要升级系统的openssl版本:
tar zxvf openssl-1.0.1m.tar.gz
cd openssl-1.0.1m
./config --prefix=/usr --shared
make && make install
Python-3.6.2/Modules/Setup.dist
取消如下4行注释,则支持ssl:
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
ln -s /usr/local/python36/bin/python3.6 /usr/local/bin/python3
ln -s /usr/local/python36/bin/pip3 /usr/local/bin/pip3
pip3 install --upgrade pip