1 python安装
1.1 安装依赖库
yum -y install python-devel openssl openssl-devel gcc
1.2 下载python
这里以最新的python 2.7.15为例
wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
tar -zxf Python-2.7.15.tgz
1.3 编译安装
cd Python-2.7.15
./configure --prefix=/usr/local/python2.7 --with-threads --enable-shared
make && make install
补充说明:需要编译静态库添加参数 --enable-static
1.4 备份老版本
mv /usr/bin/pip /usr/bin/pip_old
mv /usr/bin/easy_install /usr/bin/easy_install_old
mv /usr/bin/python /usr/bin/python_old
补充说明: 不存在的命令就可以不用备份,对工具或者文档进行替换时,养成良好习惯就行备份
1.5 配置新版本
ln -s /usr/local/python2.7/lib/libpython2.7.so /usr/lib
ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/lib
ln -s /usr/local/python2.7/lib/libpython2.7.so /usr/lib64
ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/lib64
ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python
1.6 测试
显示如下信息表示安装成功
Python 2.7.15 (default, Jul 3 2018, 22:25:04)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
1.7 修改yum
vi /usr/bin/yum
将 !/usr/bin/python 改成 #!/usr/bin/python2.6
补充说明:yum 安装工具只支持系统自带的python版本,修改配置文件使其可正常使用
2 安装 setuptools
2.1 下载setuptools
wget https://files.pythonhosted.org/packages/d3/3e/1d74cdcb393b68ab9ee18d78c11ae6df8447099f55fe86ee842f9c5b166c/
setuptools-40.0.0.zip
补充说明:可以去官网 (https://pypi.org/project/pip/)找你想要的版本
2.2 解压、安装
unzip setuptools-40.0.0.zip
cd setuptools-40.0.0
python setup.py install
2.3 配置新版本
ln -s /usr/local/python2.7/bin/easy_install /usr/bin/
3 安装pip
3.1 下载pip
wget https://files.pythonhosted.org/packages/ae/e8/2340d46ecadb1692a1e455f13f75e596d4eab3d11a57446f08259dee8f02/
pip-10.0.1.tar.gz
补充说明:官网 https://pypi.org/project/pip/
3.2 解压、安装
tar -xzvf pip-10.0.1.tar.gz
cd pip-10.0.1
python setup.py install
3.3 配置新版本
ln -s /usr/local/python2.7/bin/pip /usr/bin/