zoukankan      html  css  js  c++  java
  • 关于Linux自带的python2.6.6升级到2.7.10版本步骤详解

    CentOS 6 系统默认 Python 版本是:2.6.6 平时在使用中遇到很多的库要求是 2.7.x 版本的库,比如使用 ConfigParser 库,在 2.6 版本库就不支持没有 value 值的配置项,需要升级到 2.7 以上的库才行,这次就尝试升级一下 Python 到 2.7.x 版本,记录于此。

    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

    四、安装 ipython

    [root@vip ~]# pip install ipython==1.2.1
    [root@vip ~]# ln -s /usr/local/python27/bin/ipython /usr/bin/ipython
  • 相关阅读:
    selenium 浏览器操作
    selenium 4.0新特性及新旧api对比
    Selenium123介绍
    selenium元素定位(三) css定位方法
    selenium 安装和启动
    Selenium元素定位(一)30+1+5种方式
    软件开发经验收集
    spring+hibernate架构中Dao访问数据库的几种方法
    某励志书4
    PHP的Foreach
  • 原文地址:https://www.cnblogs.com/python8/p/14183848.html
Copyright © 2011-2022 走看看