Python2与Python3共存模式

dhso
2018/05/21 14:43
统计中

确保安装依赖存在

sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

下载python3并解压

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

tar -xvJf  Python-3.6.2.tar.xz

编译安装python3

cd Python-3.6.2

./configure prefix=/usr/local/python3

sudo make

sudo make install

安装完/usr/local/ 下就有python3文件夹

将原来python改名为python2

sudo mv /usr/bin/python /usr/bin/python2

修改一些依赖python2的文件

sudo nano /usr/bin/yum

将头部 #! /usr/bin/python修改为#! /usr/bin/python2

同样的编辑 /usr/libexec/urlgrabber-ext-down文件

sudo nano /usr/libexec/urlgrabber-ext-down

将头部 #! /usr/bin/python修改为#! /usr/bin/python2

添加软链到执行目录

ln -s /usr/local/python3/bin/python3 /usr/bin/python

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

加入python3环境变量

sudo nano /etc/profile

export PYTHON3_HOME=/usr/local/python3
export PATH=${PYTHON3_HOME}/bin:$PATH

//立即生效
source /etc/profile

本文为 dhso 原创

发布在 http://blog.minws.com/python2yu-python3gong-cun-mo-shi/

如有转载,请标明来源!

作者信息
姓名:dhso
热评文章
最新评论
文章概览