CentOS7 安装Python3.6.8
1. 安装依赖环境
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
2.下载Python3.6.8
新建个/usr/local/python3文件夹
mkdir /usr/local/python3
3.在python3文件夹下下载安装包(/usr/local/python3 ),解压文件
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz tar -xvf Python-3.6.8.tar.xz
4.编译(在解压的文件夹下 /usr/local/python3/python3.6.8)
./configure --prefix=/usr/local/python3
5.安装(在解压的文件夹下 /usr/local/python3/python3.6.8)
make make install # 先make再make install
6.创建新版本的软链接
修改旧版本
mv /usr/bin/python /usr/bin/python_bak mv /usr/bin/pip /usr/bin/pip_bak
创建新版本的软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
7.检查python的版本
python -V
8.不过,由于yum是py2写的,所以更换完python路径后,yum可能会出现错误
所以要修改配置文件
vim /usr/bin/yum vim /usr/libexec/urlgrabber-ext-down
如果没有gcc和make报错就用yum安装
yum installl gcc make -y
我这是在容器里用centos7.6镜像安装的,没有配置pip的环境变量,直接就可以使用。执行
pip list 或者pip --version
参考:https://www.cnblogs.com/klsw/p/11106166.html