码迷,mamicode.com
首页 > 编程语言 > 详细

CentOS7安装python3.6保留python2.7

时间:2018-03-19 13:41:52      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:python   Linux   CentOS   pip   

python3.6环境搭建

安装依赖

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 gcc libffi-devel python-devel openssl-devel libcurl-dev libcurl-devel

获取tgz包(以3.6.4为例)

wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

解压并切换目录

tar -zxvf Python-3.6.4.tgz
cd Python-3.6.4

执行安装

./configure --prefix=/usr/local
./configure --enable-optimizations
make && make install

创建Python3的软链接

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

创建Pip3的软链接

ln -s /usr/local/bin/pip3 /usr/bin/pip3

由于CentOS7默认安装python2.7.5,有些同学想要更新成最新版本(此处以目前最新版本2.7.14为例)

python2.7.14环境搭建

获取tgz包(以2.7.14为例)

wget https://www.python.org/ftp/python/2.7.14//Python-2.7.14.tgz

解压并切换目录

tar -zxvf Python-2.7.14.tgz
cd Python-2.7.14

执行安装

./configure --prefix=/usr/local
./configure --enable-optimizations
make && make install

将老版本python更换,并更换PATH路径

mv /usr/bin/python /usr/bin/python2.7.5
export PATH="/usr/local/bin:$PATH"

创建python2.7.14软连接

ln -s /usr/local/bin/python2.7  /usr/bin/python

创建Pip2的软链接

ln -s /usr/local/bin/pip2 /usr/bin/pip2

更改yum的python依赖

?注:作者把默认python的软连接改为2.7.5了,以下以2.7.5示例

cd /usr/bin
ls yum*

yum yum-builddep yum-config-manager yum-debug-dump yum-debug-restore yumdownloader yum-groups-manager

更改以上文件头为

#!/usr/bin/python 改为 #!/usr/bin/python2.7.5

此时便大功告成了!

CentOS7安装python3.6保留python2.7

标签:python   Linux   CentOS   pip   

原文地址:http://blog.51cto.com/12208058/2088431

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!