Python3、setuptools、Pip3安装详解

来源:互联网 发布:知乎钓鱼岛问题 编辑:程序博客网 时间:2024/05/17 00:12

博客核心内容:

1、Python3安装2、setuptools安装3、Pip3安装

之所以写这篇博客,也是有很多原因了,每次安装都要从网上各种百度,网上的答案也是各种各样,于是决定好好总结一下,下面是我在安装的过程中参考的几篇博客,附上相应的链接:
http://www.cnblogs.com/rookie404/p/6142151.html
http://www.cnblogs.com/wenchengxiaopenyou/p/5709218.html
https://seofangfa.com/python-note/setuptools-compression-requires-the-missing-zlib-module.html
http://daiqingyang.blog.51cto.com/1070509/1275432/
好的,接下来进入文章的正题:
linux下安装python3
不建议卸载python2 可能会导致系统内其他软件无法使用.
1、下载
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0a1.tar.xz
2、解压
tar xvf Python-3.6.0a1.tar.xz
3、编译安装
进入目录Python-3.6.0a1,执行以下两个命令:
./configure
make && make install
4、测试
输入python3:

[root@iz2zea81ksgk8xh72ofrr0z tmp]# python3Python 3.6.0a1 (default, Aug 19 2017, 14:53:46) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> 

如果显示上面的内容,说明安装成功。
部分截图:
这里写图片描述


接下来我们来安装setuptools,到这里面遇到了开始遇到坑了。
1、下载
wget –no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
2、解压
tar -zxvf setuptools-19.6.tar.gz

[root@iz2zea81ksgk8xh72ofrr0z software]# ll |grep setuptools-19.6drwxr-xr-x 10  501 games    4096 Aug 19 17:34 setuptools-19.6-rw-r--r--  1 root root   641502 Jan 25  2016 setuptools-19.6.tar.gz

3、进入setuptools-19.6编译安装

cd setuptools-19.6.tar.gzpython3 setup.py buildpython3 setup.py install

到这里如果你还没有报错的话,说明setuptools已经安装成功了,但是在这里我遇到了一个坑,当我执行python3 setup.py install时出现了错误,报错信息如下:

Compression requires the (missing) zlib module.

出错原因:提示的很清楚,缺少 zlib模块导致安装失败
处理方式:
1、先安装缺少的模块(2行命令)
yum install zlib
yum install zlib-devel
2、下载zlib成功后, cd Python-3.6.0a1的目录,重新执行下面的这个命令:

make && make install

3、重新进入setuptools-19.6目录,再次执行下面的命令:

python3 setup.py install

到这里问题解决,setuptools-19.6安装成功.


接下来我们安装Pip3
1、下载
wget –no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
2、解压
tar -zxvf pip-8.0.2.tar.gz

[root@iz2zea81ksgk8xh72ofrr0z software]# ll |grep pipdrwxr-xr-x  7  501 games    4096 Aug 19 17:44 pip-8.0.2-rw-r--r--  1 root root  1130183 Aug 19 17:40 pip-8.0.2.tar.gz

3、进入pip-8.0.2目录,编译安装:

cd pip-8.0.2python3 setup.py buildpython3 setup.py install

到这里pip3就安装成功了,可以检查一下:

[root@iz2zea81ksgk8xh72ofrr0z software]# whereis pip3pip3: /usr/local/bin/pip3 /usr/local/bin/pip3.6

我当时到这里以为安装成功了,但是当执行pip3的时候,报错了,信息如下:

cannot import name HTTPSHandler.

问题:提示的很清楚,缺少 HTTPSHandler模块导致安装失败
处理方式:
1、先安装缺少的模块(2行命令)

yum install opensslyum install openssl-devel

2、下载 HTTPSHandler成功后, cd Python-3.6.0a1的目录,重新执行下面的这个命令:

make && make install

当我执行完上一行命令之后,出现了下面的日志(部分)

Ignoring indexes: https://pypi.python.org/simpleCollecting setuptoolsCollecting pipInstalling collected packages: setuptools, pip  Found existing installation: setuptools 19.6    Uninstalling setuptools-19.6:      Successfully uninstalled setuptools-19.6  Found existing installation: pip 8.0.2    Uninstalling pip-8.0.2:      Successfully uninstalled pip-8.0.2Successfully installed pip setuptools

从最后一行Successfully installed pip setuptools可以看出,我的setuptools和pip随之跟着也成功了,验证一下:

[root@iz2zea81ksgk8xh72ofrr0z software]# pip3Usage:     pip <command> [options]Commands:  install                     Install packages.  download                    Download packages.  uninstall                   Uninstall packages.  freeze                      Output installed packages in requirements format.  list                        List installed packages.  show                        Show information about installed packages.  search                      Search PyPI for packages.  wheel                       Build wheels from your requirements.  hash                        Compute hashes of package archives.  completion                  A helper command used for command completion  help                        Show help for commands.General Options:  -h, --help                  Show help.  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.  -V, --version               Show version and exit.  -q, --quiet                 Give less output.  --log <path>                Path to a verbose appending log.  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).  --timeout <sec>             Set the socket timeout (default 15 seconds).  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.  --cert <path>               Path to alternate CA bundle.  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the                              certificate in PEM format.  --cache-dir <dir>           Store the cache data in <dir>.  --no-cache-dir              Disable the cache.  --disable-pip-version-check                              Don't periodically check PyPI to determine whether a new version of pip is available for                              download. Implied with --no-index.

OK,大功告成!
总结一下注意的点,每次安装完缺少的模块之后,都需要:cd Python-3.6.0a1的目录,重新执行下面的这个命令:

make && make install
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 孕吐伤了胃疼怎么办 孕期吐的胃疼怎么办 买的巧克力化了怎么办 跑步后脸上出盐怎么办 头发被剪的很短怎么办 孩子做事情拖拉不专注怎么办 新热水壶有味道怎么办 新买电热壶有味怎么办 两个月狗耳朵臭怎么办 狗狗牙齿变黄怎么办 人用了狗沐浴露怎么办 狗狗吞食牙膏吐怎么办? 狗狗吞食了牙膏怎么办 大猪拉稀不吃食怎么办 猪不发烧不吃食怎么办 天天吃自热米饭怎么办 喝了加热包水怎么办啊 蛋挞没有盒子装怎么办 塑料饭盒盖子被吸住了怎么办 火腿淹的有臭味怎么办 微波炉热饭盖子打不开怎么办 夏天带饭容易馊怎么办? 保温饭盒里有气打不开怎么办 保温饭盒摔了一下打不开怎么办 饭盒跟盖子盖一起打不开怎么办 玻璃杯子盖被水吸住打不开怎么办 电饭煲热剩饭没加水怎么办 微波炉碗盖子吸住了怎么办 微波炉转饭盖子吸住了怎么办 玻璃碗放进微波炉打不开怎么办 乐扣微波炉加热后打不开怎么办 美的微波炉盖子打不开怎么办 美的微波炉门都打不开了怎么办 饭煮好了有异味怎么办 一正常吃饭就胖怎么办 高铁盒饭没15的怎么办 上火车前票丢了怎么办 减肥期吃了汉堡怎么办 寿司店鳗鱼有刺怎么办 吃泡面胃难受该怎么办 吃上火的东西脸上长痘痘怎么办