CentOS7安装python3.6保留python2.7
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7安装python3.6保留python2.7相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章