一、环境
1、操作系统:CentOS release 6.8 (Final)
2、预安装环境:python 2.7
二、安装Python:
系统自带的有Python环境,首先需要确定当前的版本,因为一些依赖关系,不能直接进行删除卸载操作,这样有可能会导致其他的依赖关系出现问题
1、查看当前的Python版本
[root@localhost ~]# python -V
2、将所有的软件升级,升级到最新的版本
[root@localhost ~]# yum -y update
[root@localhost ~]# yum groupinstall -y development
[root@localhost ~]# yum install -y zlib zlib-dev openssl openssl-devel sqlite sqlite-devel bzip bzip2-devel mysql-devel
3、线下载Python安装包,解压缩
[root@localhost ~]# wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
[root@localhost ~]# tar -xvf Python-2.7.6.tar.xz
[root@localhost ~]# cd Python-2.7.6
[root@localhost ~]# ./configure
[root@localhost ~]# make && make altinstall
[root@localhost ~]# mv /usr/bin/python /usr/bin/python2.6.6
[root@localhost ~]# ln -s /usr/local/bin/python2.7 /usr/bin/python
修改一个文件,将连接指向新安装的Python版本
[root@localhost ~]# vi /usr/bin/yum
在这个文件中做如下修改:#!/usr/bin/python 改为 #!/usr/bin/python2.6.6
三、安装pip
1、先安装setuptools:
[root@localhost ~]# wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz
[root@localhost ~]# cd setuptools-1.4.2
[root@localhost ~]# python setup.py install
[root@localhost ~]# ln -s /usr/local/bin/easy_install-2.7 /usr/bin/easy_install
[root@localhost ~]# easy_install pip
结束
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python2.7