contos6下 python3.5手动安装pip

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liuxiao723846/article/details/84947609

1、更换centos的yum源:

1)备份老的yum源

mkdir /tmp/yum
mv /etc/yum.repos.d/*.repo /tmp/yum

2)下载新的CentOS-Base.repo 到/etc/yum.repos.d/

#centos5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

#centos6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

#centos7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3)生成yum缓存

yum makecache

2、安装pip和setuptools:

丰富的第三方库是python的优势所在,pip可以解决我们在下载第三方库时的依赖关系。我们使用yum安装pip:

yum -y install python-pip

报如下错误:

所以,我们选择手动安装pip。

注:在安装pip的时候,需要先安装setuptools

1)下载、解压setuptools:

cd /usr/local
wget --no-check-certificate  https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26

tar -zxvf setuptools-19.6.tar.gz

2)安装setuptools:

cd setuptools-19.6
python setup.py build
python setup.py install

可能会报如下错误:

报错: RuntimeError: Compression requires the (missing) zlib module

解决:我们需要在linux中安装zlib-devel包,进行支持。

yum install zlib-devel

然后需要对python3.5进行重新编译安装:

cd /usr/local/src/Python-3.5.2
make & make install

又是漫长的编译安装过程。。。成功后,重新使用python setup.py install 安装setuptools即可。

3)下载、解压pip:

cd /usr/local
wget --no-check-certificate  https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-8.0.2.tar.gz

4)安装pip:

cd pip-8.0.2
python setup.py build
python setup.py install

3、使用pip安装第三方:

python3 -m pip install paramiko
...
报错:ImportError: cannot import name 'HTTPSHandler'

解决:

yum install openssl-devel

然后再次重新编译python。

cd /usr/local/src/Python-3.5.2
make & make install

漫长等待后,ok,我们终于完成了整个python3环境的安装。

参考:https://blog.csdn.net/qihongchao/article/details/80524630

猜你喜欢

转载自blog.csdn.net/liuxiao723846/article/details/84947609