标签:django pip
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. 解压文件
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软件包管理工具
下面安装pip:
安装之前:先安装openssl openssl-devel,后面你就会知道
https://pip.pypa.io/en/latest/installing.html
pip使用文档:
https://pypi.python.org/pypi/pip#downloads
我安装和下载:
[root@centos pip-1.5.6]# pwd
/tmp/pip-1.5.6
[root@centos pip-1.5.6]# ls
AUTHORS.txt docs pip.egg-info setup.cfg
build LICENSE.txt PKG-INFO setup.py
CHANGES.txt MANIFEST.in PROJECT.txt setuptools-8.0.4
dist pip README.rst setuptools-8.0.4.zip
报错: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
解决:
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"
本文出自 “8176010” 博客,转载请与作者联系!
标签:django pip
原文地址:http://8186010.blog.51cto.com/8176010/1591168