Python,作为现在运维人员必备的技能,在现在很多的运维工具、云计算、虚拟化上都用到了python,这使得python编程语言在TIOBE上地位一再上升;python的快速上手,简单易学,丰富的库使得它越来越受人们欢迎。
今天安装pip之后,在通过pip安装其他包的时候,提示python版本太低了,我直接进行了python的升级(python 2.7.8,结果
)
# pip
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
错误发生的原因是,系统python的版本已经是2.7版本了,但是pip引用的还是老版本,所以导致了,找不到模块
1、卸载pip
# rpm -qa|grep python-pip | xargs rpm -e --nodeps
2、下载依赖包
# yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel
3、下载python2.7.8
# wget --no-check-certificate https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
# tar xvzf Python-2.7.8.tgz
# cd Python-2.7.8
# ./configure --prefix=/usr/local
# make --jobs=`grep processor /proc/cpuinfo | wc -l`
# make install
4、调整yum
# vim /usr/bin/yum
#!/usr/bin/python => #!/usr/bin/python2.6
指向系统原来老版本的python,防止yum的时候出错
5、安装pip
1、下载pip源码包安装
# wget "https://bitbucket.org/pypa/setuptools/raw/bootstrap(引导程序)/ez_setup.py"
# /usr/local/bin/python2.7 ez_setup.py
# /usr/local/bin/easy_install-2.7 pip
2、通过更新yum源来安装
# wget --no-check-certificate http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
# yum clean expire-cache
# yum update
# yum install python-pip -y
6、引用python2.7
1、直接将python2.7添加到环境变量中 .bashrc
2、通过软链接实现
# ln -sf /usr/local/bin/python2.7 /usr/bin/python2.7
# ln -sf /usr/local/bin/pip /usr/local/bin/pip2.7
参考文章:
http://stackoverflow.com/questions/24795955/install-pip-failed
http://linuxsogood.org/816.html