运维开发网

centos7.4安装python3.7.6 不卸载python2

运维开发网 https://www.qedev.com 2021-02-05 13:30 出处:51CTO 作者:wx5a2e44e86b01d
安装包:https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz安装依赖关系yum-ygroupinstall"Developmenttools"yum-yinstallzlib-develbzip2-developenssl-develncurses-develsqlite-develreadline-develtk-develgdb

安装包:

https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz

安装依赖关系

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

解压文件并开始安装

mkdir -p /ops/inst && cd /ops/inst
wget -P /ops/inst https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz
tar -xf /ops/inst/Python-3.7.6.tar.xz
mkdir /usr/local/python3
cd /ops/inst/Python-3.7.6
./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl 
make && make install
if [ $? -ne 0 ];then
    echo "安装失败,请检查make程序"
else
    ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
    ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
    ln -s /usr/local/bin/python3  /usr/bin/python
        echo "python3.7.6安装完成,请执行python3 -V 验证!"
fi

修改yum引用Python2

#修改 /usr/bin/yum
sed -i 's|#!/usr/bin/python|#!/usr/bin/python2|g' /usr/bin/yum

#修改 /usr/libexec/urlgrabber-ext-down
sed -i 's|#!/usr/bin/python|#!/usr/bin/python2|g' /usr/libexec/urlgrabber-ext-down

此时Python3和Python2共存。

0

精彩评论

暂无评论...
验证码 换一张
取 消