1)安装devtoolset
yum groupinstall "Development tools"
2)安装编译Python需要的包包
yum -y install zlib-devel yum -y install bzip2-devel yum -y install openssl-devel yum -y install ncurses-devel yum -y install sqlite-devel
3)下载并解压Python 2.7.9的源代码
cd /opt wget --no-check-certificate https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz tar xf Python-2.7.9.tar.xz cd Python-2.7.9
4)编译与安装Python 2.7.9
./configure --prefix=/usr/local make && make altinstall
5)建议软链接备份python 2.6.6
mv /usr/bin/python /usr/bin/python2.6.6 ln -s /usr/local/bin/python2.7 /usr/bin/python python -V
6)修正yum引用python版本
vim /usr/bin/yum
将文件头部的
#!/usr/bin/python
改为如下内容
#!/usr/bin/python2.6.6
7) 安装pip,setup_tool:
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz tar -xvf setuptools-1.4.2.tar.gz cd setuptools-1.4.2 python2.7 setup.py install
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-6.0.7.tar.gz tar zxvf pip-6.0.7.tar.gz cd pip-6.0.7 python setup.py install
安装完成之后,执行如下命令:
pip --version
报错如下:
[root@iZ23zgmzp6vZ pip-6.0.7]# pip --version
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2797, in <module>
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 576, in resolve
pkg_resources.DistributionNotFound: pip==7.1.0
解决办法:
easy_install pip==7.1.0
另外可以参考如下方法安装pip:
安装pip
下载最新版的pip,然后安装
wget https://bootstrap.pypa.io/get-pip.py python get-pip.py
查找pip的位置
whereis pip
找到pip2.7的路径,为其创建软链作为系统默认的启动版本
ln -s /usr/local/bin/pip2.7 /usr/bin/pip
pip安装完毕,现在可以用它下载安装各种包了
文章的脚注信息由WordPress的wp-posturl插件自动生成
来自外部的引用: 1