Centos6.5中实现python2与python3的并存

前端之家收集整理的这篇文章主要介绍了Centos6.5中实现python2与python3的并存前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

linux下python的安装

安装步骤如下

1 准备编译环境

yum groupinstall 'Development Tools'

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel sqlit

2 下载 Python3.5代码

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

3 编译

tar Jxvf Python-3.5.2.tar.xz

cd Python-3.5.2

./configure --prefix=/usr/local/python3

make && make install

4 设置环境变量

echo 'export PATH=$PATH:/usr/local/python3/bin' >> ~/.bashrc

5 设置目录(这样做的目的是在系统任意目录敲入python3调用的是python3.5的命令)

mv /usr/bin/python /usr/local/python.bak

rm -rf /usr/local/python2

ln -sv /usr/local/python2.6 /usr/bin/python2

ln -sv /usr/local/python3/bin/python3.5 /usr/bin/python

6 修改yum脚本,使其指向旧版本的python,已避免yum无法运行

sed -i 's$#!/usr/bin/python$#!/usr/bin/python2.6$g' /usr/bin/yum

7 测试

输入python 显示如下

wKioL1mmh4vDrtwaAAAiEiQNoz0936.png-wh_50

wKiom1mmh6CB9R02AAAiTVNEqtE337.png-wh_50

猜你在找的CentOS相关文章