linux运维、架构之路-python2.6升级3.6

一、环境

1、系统

[root@m01 ~]# cat /etc/redhat-release 
CentOS release 6.9 (Final)
[root@m01 ~]# uname -r
2.6.32-696.el6.x86_64

2、当前python版本

Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /usr/lib64/python2.6/lib-dynload/readline.so
>>>

二、升级

1、安装devtoolset

yum groupinstall "Development tools" -y

2、安装编译Python需要的包

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

3、下载并解压Python 3.6.0的源代码

cd /server/tools/
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar xf Python-3.6.0.tar.xz 
cd Python-3.6.0

4、编译与安装Python 3.6.0

./configure --prefix=/usr/local
make && make altinstall

5、配置系统pyhon默认指向python3.6.0

###备份###
mv /usr/bin/python /usr/bin/python2.6_temp
###创建软连接###
ln -s /usr/local/bin/python3.6 /usr/bin/python

6、查看python版本

[root@m01 ~]# python -V
Python 3.6.0

7、配置环境变量

[root@m01 ~]# tail -2 /etc/profile
PY_HOME=/usr/local/bin/python3.6.0
export PATH=$PY_HOME/bin:$PATH

source /etc/profile#使环境变量生效

8、查看环境变量Python路径是否已存在

[root@m01 ~]# echo $PATH
/usr/local/bin/python3.6.0/bin:/usr/local/bin/python2.7/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

至此Python完美升级

三、遇到的问题

有时候python升级完后,会出现yum与python新版本不兼容的情况,需要修改yum文件

vim /usr/bin/yum
把"!/usr/bin/python"改为"!/usr/bin/python2.6"

posted @ 2018-06-06 15:29  闫新江  阅读(637)  评论(0编辑  收藏  举报