rtwer 发表于 2014-12-18 08:31:09

升级python,安装pip,Django

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
http://www.python.org/ftp/python/2. 解压文件
tarxvf Python-2.7.9.tar.bz23. 创建安装目录
mkdir/usr/local/python274. 安装python
./configure--prefix=/usr/local/python27
make
make install5. 修改老版本的ln指向(注意:这里修改后,可能会影响yum的使用)
[root@centospip-1.5.6]# mv /usr/bin/python /usr/bin/python2.6.6# ln -s /usr/local/python27/bin/python/usr/bin/python
报错:# yum clean allThere was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, orverify that the module is installed correctly.
It's possible that the above module doesn't match thecurrent version of Python, which is:2.7.9 (default, Dec 17 2014, 16:50:28)
If you cannot solve this problem yourself, please go tothe yum faq at:http://yum.baseurl.org/wiki/Faq
错误原因:错误信息描述为yum 所依赖的python不相符,请安装相对应的python即可
# rpm -qa | grep yumyum-metadata-parser-1.1.2-16.el6.x86_64yum-plugin-fastestmirror-1.1.30-30.el6.noarchPackageKit-yum-0.5.8-23.el6.x86_64yum-3.2.29-60.el6.centos.noarchyum-plugin-security-1.1.30-30.el6.noarchPackageKit-yum-plugin-0.5.8-23.el6.x86_64yum-utils-1.1.30-30.el6.noarchYou have new mail in /var/spool/mail/root
# whereis pythonpython: /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# python -VPython 2.7.9
现在系统上有两个版本的python!!!yum是由python写的!一个是我刚安装的2.7.9,一个是centos默认安装的2.6.6但是我执行了:# mv /usr/bin/python /usr/bin/python2.6.6# ln -s /usr/local/python27/bin/python/usr/bin/python# python -VPython 2.7.9
# which yum/usr/bin/yum   这个文件使用了python,看来这个yum不支持,2.7.9高版本的python解决:# vim /usr/bin/yum把python环境改成python2.6.6
pip:python软件包管理工具下面安装pip:安装之前:先安装opensslopenssl-devel,后面你就会知道https://pip.pypa.io/en/latest/installing.html
pip使用文档:https://pypi.python.org/pypi/pip#downloads
我安装和下载:# pwd/tmp/pip-1.5.6# lsAUTHORS.txtdocs         pip.egg-infosetup.cfgbuild      LICENSE.txtPKG-INFO      setup.pyCHANGES.txtMANIFEST.inPROJECT.txt   setuptools-8.0.4dist         pip          README.rst    setuptools-8.0.4.zip
报错:ImportError:cannot import name HTTPSHandler# pipTraceback (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_pointFile "build/bdist.linux-x86_64/egg/pkg_resources.py",line 2545, in load_entry_pointFile "build/bdist.linux-x86_64/egg/pkg_resources.py",line 2244, in loadFile"/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_progFile"/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 versionFile"/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_typesFile"/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
解决:yuminstall -y openssl   openssl-devel然后重新编译python!!
安装Django:版本:1.7.1# pipinstall DjangoDownloading/unpacking DjangoDownloadingDjango-1.7.1-py2.py3-none-any.whl (7.4MB):20%1.5MB
但是,悲剧的是:python升级之后,KVM的图形管理界面就打不开了,但是KVM虚拟机都没有挂掉,只是说,图形管理界面挂了!!!
报错:
#virt-manager
Traceback (most recent calllast):
File"/usr/share/virt-manager/virt-manager.py", line 400, in<module>
main()
File"/usr/share/virt-manager/virt-manager.py", line 251, inmain
from virtManager importcli
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

解决:
#/usr/bin/python2.6.6 -V
Python 2.6.6
#/usr/bin/python2.7 -V
Python 2.7.9

使用python2.6.6启动virt-manager:
#/usr/bin/python2.6.6 "/usr/share/virt-manager/virt-manager.py"


页: [1]
查看完整版本: 升级python,安装pip,Django