Python2离线安装python2,pip

参考链接: Linux安装python2.7、pip和setuptools: https://www.cnblogs.com/xiaowenshu/p/10239834.html

安装python

官网下载python2: https://www.python.org/downloads/

编译安装:

# 安装依赖库
yum install gcc g++ zlib zlib-devel openssl-devel
# 解压
tar -zxvf Python-2.7.14.tgz
# 创建安装文件夹
mkdir /usr/local/python27
# 编译安装
cd Python-2.7.14
./configure --prefix=/usr/local/python27/ 
make
make install

替换默认的python

ln -s  /usr/local/python27/bin/python2.7 /usr/bin/python
ln -s  /usr/local/python27/bin/python2.7 /usr/bin/python2
ln -s  /usr/local/python27/bin/python2.7 /usr/bin/python27
ln -s  /usr/local/python27/bin/python2.7 /usr/bin/python2.7

查看是否替换成功
python --version

修改python版本之后yum不能用的解决方法:
修改第一行指定的解析器链接:

vi /usr/bin/yum  
#!/usr/bin/python  

安装setup-tools和pip

setuptools下载链接: https://pypi.python.org/pypi/setuptools,下载zip的文件

wget https://pypi.python.org/packages/45/29/8814bf414e7cd1031e1a3c8a4169218376e284ea2553cc0822a6ea1c2d78/setuptools-36.6.0.zip#md5=74663b15117d9a2cc5295d76011e6fd1
unzip setuptools-36.6.0.zip 
cd setuptools-36.6.0
python setup.py install

下载pip的链接: https://pypi.python.org/pypi/pip

wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
tar -zxvf pip-9.0.1.tar.gz
cd pip-9.0.1
python setup.py install

创建软链接来替换文件

rm -rf /usr/bin/easy_install* /usr/bin/pip
ln -s /usr/local/python27/bin/pip2.7 /usr/bin/pip
ln -s /usr/local/python27/bin/pip2.7 /usr/bin/pip27
ln -s /usr/local/python27/bin/pip2.7 /usr/bin/pip2.7
ln -s /usr/local/python27/bin/easy_install /usr/bin/easy_install
ln -s /usr/local/python27/bin/easy_install /usr/bin/easy_install27
ln -s /usr/local/python27/bin/easy_install /usr/bin/easy_install2.7

验证操作是否成功
pip --version

你可能感兴趣的:(Python2离线安装python2,pip)