CentOS6.5 升级 python 2.6.6 到 2.7.10
2018-02-11 11:23
477 查看
CentOS 6 系统默认 Python 版本是:2.6.6 平时在使用中遇到很多的库要求是 2.7.x 版本的库,比如使用 ConfigParser 库,在 2.6 版本库就不支持没有 value 值的配置项,需要升级到 2.7 以上的库才行,这次就尝试升级一下 Python 到 2.7.x 版本,记录于此。
1. 准备安装包,系统是最小化安装
2. 编译配置安装
3. 查看 python 版本信息
4. 用 python2.7 替换旧版本
5. 重新验证 Python 版本信息
可以看到,系统识别的 python 版本已经是 python 2.7.10
执行 python -V 遇到的问题:
解决:
因为 yum 是不兼容 Python 2.7 的,所以 yum 不能正常工作,我们需要指定 yum 的 Python 为 2.6。
1. 升级 python 后 yum 出现的问题
2. 编辑 yum 配置文件
3. 验证 yum 问题解决
1. 下载安装
2. 设置软连接
一、升级 Python 2.7.10 版本
1. 准备安装包,系统是最小化安装# 下载安装依赖的相关包 [root@vip ~]# yum install vim gcc make wget -y [root@vip ~]# yum install openssl-devel zlib-devel readline-devel sqlite-devel -y
# 下载 [root@vip ~]# cd /usr/local/src [root@vip ~]# wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz # 解压 [root@vip ~]# tar -zxvf Python-2.7.10.tgz [root@vip ~]# ls Python-2.7.10 Python-2.7.10.tgz
2. 编译配置安装
[root@vip ~]# cd Python-2.7.10 [root@vip Python-2.7.10]# ./configure --enable-shared --enable-loadable-sqlite-extensions \ --prefix=/usr/local/python27 --with-zlib --with-ssl [root@vip Python-2.7.10]# vim ./Modules/Setup # 找到下边这一行内容,去掉注释 #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz [root@vip Python-2.7.10]# make && make install
3. 查看 python 版本信息
[root@vip Python-2.7.10]# python -V Python 2.6.6 # 版本依旧是 2.6.6
4. 用 python2.7 替换旧版本
[root@vip Python-2.7.10]# cd /usr/bin/ [root@vip bin]# ls python* -l # 旧 python 版本信息 -rwxr-xr-x. 2 root root 4864 2月 22 2013 python lrwxrwxrwx. 1 root root 6 10月 22 18:38 python2 -> python -rwxr-xr-x. 2 root root 4864 2月 22 2013 python2.6
[root@vip bin]# mv /usr/bin/python /usr/bin/python2.6.6 [root@vip bin]# ln -s /usr/local/python27/bin/python2.7 /usr/bin/python
[root@vip bin]# ls python* -l lrwxrwxrwx. 1 root root 33 10月 23 00:01 python -> /usr/local/python27/bin/python2.7 lrwxrwxrwx. 1 root root 6 10月 22 18:38 python2 -> python -rwxr-xr-x. 2 root root 4864 2月 22 2013 python2.6 -rwxr-xr-x. 2 root root 4864 2月 22 2013 python2.6.6
5. 重新验证 Python 版本信息
[root@vip bin]# python -V Python 2.7.10
可以看到,系统识别的 python 版本已经是 python 2.7.10
执行 python -V 遇到的问题:
python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory # 原因:linux系统默认没有把/usr/local/python27/lib路径加入动态库搜索路径
解决:
[root@vip ~]# vim /etc/ld.so.conf # 添加如下一行内容 /usr/local/python27/lib [root@vip ~]# ldconfig # 使新添加的路径生效
二、解决 yum 兼容性问题
因为 yum 是不兼容 Python 2.7 的,所以 yum 不能正常工作,我们需要指定 yum 的 Python 为 2.6。1. 升级 python 后 yum 出现的问题
[root@vip bin]# yum There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: No module named yum ... ... ... ...
2. 编辑 yum 配置文件
[root@vip bin]# vim /usr/bin/yum #!/usr/bin/python # 第一行修改为 python2.6.6 #!/usr/bin/python2.6.6
3. 验证 yum 问题解决
[root@vip bin]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile ... ... ... ...
三、升级 python 后,安装 pip 工具
1. 下载安装[root@vip ~]# wget https://bootstrap.pypa.io/get-pip.py [root@vip ~]# python get-pip.py
2. 设置软连接
[root@vip ~]# ln -s /usr/local/python27/bin/pip2.7 /usr/bin/pip
相关文章推荐
- centos6.5 下 python2.6.6升级至python2.7.12
- Centos 6.5 python 2.6.6 升级到 2.7.3,并安装easy_install和pip工具过程
- centos6.5系统下将Python2.6.6升级为Python3.5.0
- centos6.5将python2.6.6升级到python2.7以及easy_install和pip
- centos6.5 升级python2.6.6到2.7.9安装过程出现问题解决过程
- Centos默认的python2.6.6升级到python2.7.10全过程(包含setuptools/pip/django/yum设置)
- CentOS 6.3 64bit上升级系统默认Python 2.6.6到2.7.10版本
- Centos6.5 python2.6.6升级2.7.13,安装setuptools和pip
- centos6.5系统将Python2.6.6升级到3.6.3版本
- CentOS6.5自带Python2.6.6升级至Python2.7
- centos升级默认python2.6.6到2.7.9版本
- CentOS环境 升级Python2.6.6至2.7.6
- Centos 6.4 python 2.6.6 升级到 2.7.6
- CentOS6.5默认Python版本升级到python2.7.5
- CentOS环境 升级Python2.6.6至2.7.5
- centos6.5 系统上升级2.6.6到2.7.12
- CentOS6.5 升级 Python 2.7 版本
- CentOS 环境中 python的升级步骤 处理 2.6.6 到 3.6.4
- centos6.5 升级python2.7.6
- [置顶] centos6.5 解决python2.6.6交互模式下方形键和退格键乱码的情况