Centos 安装python 3.7 ,同时兼容python2.7
下载Python源码
从http://www.python.org/download/根据需要的版本下载源文件。
例如上图就是我在官网直接找到3.5.6版本的下载页面,点击的tar源码包进行下载。
1. 安装依赖环境
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
# yum install gcc
yum install libffi-devel -y
yum install mysql-devel gcc gcc-devel python-devel -y
# tar -zxvf Python-3.6.1.tgz
进入解压后的目录,编译安装。
cd Python-3.6.1
./configure --prefix=/usr/local/python3
make && make install
如果 报错
ModuleNotFoundError: No module named ‘_ctypes’ make: *** [install] Error 1
yum install libffi-devel -y 《-安装这个就能解决
建立python3的软链
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
检查Python3及pip3是否正常可用:
python3 -V
pip3 -V
https://www.cnblogs.com/tielemao/p/9480611.html
https://www.cnblogs.com/kimyeee/p/7250560.html
http://www.kaaer.cn/archives/811