先去python官网下载python3安装包:www.python.org
找到适合自己机器版本的包
执行命令:
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
安装相关编译工具
yum -y groupinstall "Development tools"
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 libffi-devel
解压安装包:
tar -xvf Python-3.7.3.tgz
创建编译文件路径
mkdir /usr/local/python3 //在local目录下创建python3目录
cd /usr/local/Python-3.7.3 //转到解压目录下
//配置安装目录
./configure --prefix=/usr/local/python3
如果显示如上图所示的错误,只需执行:yum -y install gcc
安装gcc后再次执行上述命令即可
编译源码
make && make install
配置软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
检验:
python3 -V
pip3 -V
`
ERROR:
1、安装python3.7出现ModuleNotFoundError: No module named ‘_ctypes’解决办法
yum install libffi-devel -y
2、zipimport.ZipImportError: can’t decompress data
yum -y install zlib*