Install Python pip on RHEL7.1
关于Pip的安装,之前的文档中有描述过在MS Windows下的实现方式:
而在Linux下,同样是可以实现Pip的,它的官方说明文档为:
https://pip.pypa.io/en/latest/installing.html
在我的环境中,实现具体如下所示:
首先,你需要从官方获取“get-pip.py”的文本文件:https://bootstrap.pypa.io/get-pip.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
[root@adamhuanlinux ~]# cd /software [root@adamhuanlinux software]# ls pcre2-10.00 pcre2-10.00.tar.gz yum_data zlib-1.2.8 zlib-1.2.8.tar.gz [root@adamhuanlinux software]# mkdir python [root@adamhuanlinux software]# ls pcre2-10.00 pcre2-10.00.tar.gz python yum_data zlib-1.2.8 zlib-1.2.8.tar.gz [root@adamhuanlinux software]# cd python/ [root@adamhuanlinux python]# ls [root@adamhuanlinux python]# pwd /software/python [root@adamhuanlinux python]# [root@adamhuanlinux python]# wget https://bootstrap.pypa.io/get-pip.py --2015-04-11 09:37:01-- https://bootstrap.pypa.io/get-pip.py 正在解析主机 bootstrap.pypa.io (bootstrap.pypa.io)... 103.245.222.175 正在连接 bootstrap.pypa.io (bootstrap.pypa.io)|103.245.222.175|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:1420671 (1.4M) [text/x-python] 正在保存至: “get-pip.py” 100%[==================================================================================================>] 1,420,671 35.7KB/s 用时 44s 2015-04-11 09:37:46 (31.8 KB/s) - 已保存 “get-pip.py” [1420671/1420671]) [root@adamhuanlinux python]# [root@adamhuanlinux python]# ls get-pip.py [root@adamhuanlinux python]# du -sh * 1.4M get-pip.py [root@adamhuanlinux python]# [root@adamhuanlinux python]# cat get-pip.py | wc -l 17853 [root@adamhuanlinux python]# |
然后,你需要用管理员权限(在Linux中使用root)执行指令:pythonX get-pip.py
1 2 3 4 5 6 7 8 9 |
[root@adamhuanlinux python]# python2.7 get-pip.py /tmp/tmp6OufiC/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. Collecting pip /tmp/tmp6OufiC/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. Downloading pip-6.1.1-py2.py3-none-any.whl (1.1MB) 100% |████████████████████████████████| 1.1MB 97kB/s Installing collected packages: pip Successfully installed pip-6.1.1 [root@adamhuanlinux python]# |
这样,Pip就被成功安装好了。
在Pip成功安装之前,系统是无法找到“pip”指令的:
1 2 3 |
[root@adamhuanlinux local]# pip bash: pip: 未找到命令... [root@adamhuanlinux local]# |
成功安装后的状态:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[root@adamhuanlinux python]# pip Usage: pip <command> [options] Commands: install Install 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. zip DEPRECATED. Zip individual packages. unzip DEPRECATED. Unzip individual packages. 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. [root@adamhuanlinux python]# |
Pip被安装到了哪里?
1 2 3 |
[root@adamhuanlinux python]# whereis pip pip: /usr/bin/pip /usr/bin/pip2.7 [root@adamhuanlinux python]# |
可以看到,Pip位于:/usr/bin。
Pip的使用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
[root@adamhuanlinux python]# pip install nose Collecting nose /usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Downloading nose-1.3.6-py2-none-any.whl (154kB) 100% |████████████████████████████████| 155kB 319kB/s Installing collected packages: nose Successfully installed nose-1.3.6 [root@adamhuanlinux python]# [root@adamhuanlinux python]# pip install virtualenv Collecting virtualenv /usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Downloading virtualenv-12.1.1-py2.py3-none-any.whl (1.6MB) 100% |████████████████████████████████| 1.6MB 68kB/s Installing collected packages: virtualenv Successfully installed virtualenv-12.1.1 [root@adamhuanlinux python]# [root@adamhuanlinux python]# pip install distribute Collecting distribute /usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Downloading distribute-0.7.3.zip (145kB) 100% |████████████████████████████████| 147kB 71kB/s Requirement already satisfied (use --upgrade to upgrade): setuptools>=0.7 in /usr/lib/python2.7/site-packages (from distribute) Installing collected packages: distribute Running setup.py install for distribute Successfully installed distribute-0.7.3 [root@adamhuanlinux python]# |
————————————————————————————————
Done。