升级python,安装pip,Djang

发布时间:2019-09-17 07:43:02编辑:auto阅读(1992)

    centos6.6 系统默认python版本是python2.6.6.目前这个版本算很低了,主流是使用python2.7或者python3.0了;python2.6.6仅可以支持到Django1.3.7,这个Django版本也太低了,很多特性不可使用,现在就升级到python2.6.6到python2.7.9,然后安装pip,通过pip安装Django的高版本!



    1. 下载python2.7.9
    # wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz

    2. 解压文件
    tar xvf Python-2.7.9.tar.bz2

    3. 创建安装目录
    mkdir /usr/local/python27

    4. 安装python
    ./configure --prefix=/usr/local/python27
    make
    make install

    5. 修改老版本的ln指向(注意:这里修改后,可能会影响yum的使用)
    [root@centos pip-1.5.6]# mv /usr/bin/python /usr/bin/python2.6.6

    [root@centos pip-1.5.6]# ln -s /usr/local/python27/bin/python /usr/bin/python



    报错:

    [root@centos pip-1.5.6]# yum clean all

    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


    Please install a package which provides this module, or

    verify that the module is installed correctly.


    It's possible that the above module doesn't match the

    current version of Python, which is:

    2.7.9 (default, Dec 17 2014, 16:50:28)

    [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]


    If you cannot solve this problem yourself, please go to

    the yum faq at:

    http://yum.baseurl.org/wiki/Faq



    错误原因:错误信息描述为yum 所依赖的python不相符,请安装相对应的python即可



    [root@centos pip-1.5.6]# rpm -qa | grep yum

    yum-metadata-parser-1.1.2-16.el6.x86_64

    yum-plugin-fastestmirror-1.1.30-30.el6.noarch

    PackageKit-yum-0.5.8-23.el6.x86_64

    yum-3.2.29-60.el6.centos.noarch

    yum-plugin-security-1.1.30-30.el6.noarch

    PackageKit-yum-plugin-0.5.8-23.el6.x86_64

    yum-utils-1.1.30-30.el6.noarch

    You have new mail in /var/spool/mail/root



    [root@centos pip-1.5.6]# whereis python

    python: /usr/bin/python2.6 /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/include/python2.6 /usr/share/man/man1/python.1.gz

    [root@centos pip-1.5.6]# python -V

    Python 2.7.9



    现在系统上有两个版本的python!!!yum是由python写的!

    一个是我刚安装的2.7.9,一个是centos默认安装的2.6.6

    但是我执行了:

    [root@centos pip-1.5.6]# mv /usr/bin/python /usr/bin/python2.6.6

    [root@centos pip-1.5.6]# ln -s /usr/local/python27/bin/python /usr/bin/python

    [root@centos Downloads]# python -V

    Python 2.7.9



    [root@centos pip-1.5.6]# which yum

    /usr/bin/yum     这个文件使用了python,看来这个yum不支持,2.7.9高版本的python

    解决:

    [root@centos pip-1.5.6]# vim /usr/bin/yum

    把python环境改成python2.6.6



    pip:python软件包管理工具

    参考:

    安装之前:先安装openssl openssl-devel,后面你就会知道

    https://pip.pypa.io/en/latest/installing.html



    pip使用文档:

    https://pypi.python.org/pypi/pip#downloads


    ---------------------------------------------------------------------

    安装setuptools和pip  :

    安装setuptools:

    使用 ez_setup.py脚本安装setuptools

    wget http://peak.telecommunity.com/dist/ez_setup.py 
    python ez_setup.py   


    参考:什么是easy_install:

    http://www.cnblogs.com/huangjacky/archive/2012/03/28/2421866.html


    安装pip-1.4:后面讲如何升级pip

    wget https://pypi.python.org/packages/source/p/pip/pip-1.4.tar.gz#md5=ca790be30004937987767eac42cfa44a 

    tar -zxf pip-1.4.tar.gz && cd pip-1.4 
    python setup.py install


    PS. 记得设置%PYTHON_HOME%/Scripts/到PATH环境变量

    #vim /etc/profile

      export PATH="/usr/local/mysql/bin:/usr/local/python2.7/bin:$PATH"

    #source /etc/profile



    参考:pip的安装:

    http://blog.csdn.net/cnyyx/article/details/25614669

    参考:pip的用法

    http://www.111cn.net/sys/linux/60630.htm

    --------------------------------------------------------------------


    #pip list --outdated

    发现pip是pip-1.4版本太低可以更新:

    将pip-1.4升级到pip-1.5.6:

    # pip install --upgrade pip



    报错:ImportError: cannot import name HTTPSHandler

    [root@centos pip-1.5.6]# pip

    Traceback (most recent call last):

    File "/usr/bin/pip", line 9, in <module>

    load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()

    File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 458, in load_entry_point

    File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2545, in load_entry_point

    File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2244, in load

    File "/usr/local/python27/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/__init__.py", line 10, in <module>

    from pip.util import get_installed_distributions, get_prog

    File "/usr/local/python27/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/util.py", line 18, in <module>

    from pip._vendor.distlib import version

    File "/usr/local/python27/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/distlib/version.py", line 14, in <module>

    from .compat import string_types

    File "/usr/local/python27/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/distlib/compat.py", line 31, in <module>

    from urllib2 import (Request, urlopen, URLError, HTTPError,

    ImportError: cannot import name HTTPSHandler


    解决:安装openssl openssl-devel


    解决:

    yum install -y openssl   openssl-devel

    然后重新编译python!!



    安装Django:版本:1.7.1

    [root@centos Downloads]# pip install Django

    Downloading/unpacking Django

    Downloading Django-1.7.1-py2.py3-none-any.whl (7.4MB):  20%  1.5MB


    但是,悲剧的是:

    python升级之后,KVM的图形管理界面就打不开了,但是KVM虚拟机都没有挂掉,只是说,图形管理界面挂了!!!



    报错:

    [root@centos ~]# virt-manager

    Traceback (most recent call last):

    File "/usr/share/virt-manager/virt-manager.py", line 400, in <module>

    main()

    File "/usr/share/virt-manager/virt-manager.py", line 251, in main

    from virtManager import cli

    File "/usr/share/virt-manager/virtManager/cli.py", line 29, in <module>

    import libvirt

    ImportError: No module named libvirt

    You have new mail in /var/spool/mail/root



    解决:

    [root@centos ~]# /usr/bin/python2.6.6 -V

    Python 2.6.6

    [root@centos ~]# /usr/bin/python2.7 -V

    Python 2.7.9



    使用python2.6.6启动virt-manager :

    [root@centos ~]# /usr/bin/python2.6.6 "/usr/share/virt-manager/virt-manager.py"


关键字