感谢支持
我们一直在努力

CentOS 7下Python 3安装pip-9.0.1

pip类似RedHat里面的yum,安装Python包非常方便。本节详细介绍pip的安装、以及使用方法。

1、下载pip安装包

[root@localhost ~]# wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9

2、解压pip安装包

[root@localhost ~]# tar xf pip-9.0.1.tar.gz

3、安装pip

[root@localhost ~]# cd pip-9.0.1
[root@localhost pip-9.0.1]# python3 setup.py install

4、pip使用详解

pip安装模块报错,提示没有ssl模块

[root@localhost ipython-6.1.0]# pip install traitlets
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting traitlets
Could not fetch URL https://pypi.python.org/simple/traitlets/: There was a problem confirming the ssl certificate: Can’t connect to HTTPS URL because the SSL module is not available. – skipping
Could not find a version that satisfies the requirement traitlets (from versions: )
No matching distribution found for traitlets
#没有安装openssl-devel,然后重新编译安装python3.6
[root@localhost pip-9.0.1]# yum install openssl-devel -y
#进入python3.6解压包目录
[root@localhost Python-3.6.1]#make clean
[root@localhost Python-3.6.1]# ./configure
[root@localhost Python-3.6.1]# make && make install

安装openssl-devel并重新编译安装python3后,再次测试pip安装模块

[root@localhost ~]# pip install ‘traitlets’
Collecting traitlets
  Downloading traitlets-4.3.2-py2.py3-none-any.whl (74kB)
    100% |?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..| 81kB 87kB/s
Collecting six (from traitlets)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting ipython-genutils (from traitlets)
  Downloading ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting decorator (from traitlets)
  Downloading decorator-4.0.11-py2.py3-none-any.whl
Installing collected packages: six, ipython-genutils, decorator, traitlets
Successfully installed decorator-4.0.11 ipython-genutils-0.2.0 six-1.10.0 traitlets-4.3.2
#安装成功

pip uninstall Package:卸载模块
[root@localhost pip-9.0.1]# pip uninstall traitlets
Uninstalling traitlets-4.3.2:
……
packages/traitlets/utils/tests/test_importstring.py
Proceed (y/n)? y     
  Successfully uninstalled traitlets-4.3.2

pip freeze:按需求格式输出已安装的模块

[root@localhost pip-9.0.1]# pip freeze
decorator==4.0.11
ipython==6.1.0
ipython-genutils==0.2.0
pexpect==4.2.1
ptyprocess==0.5.2
Pygments==2.2.0
six==1.10.0
traitlets==4.3.2

pip list  –format=(legacy|columns):安装指定格式输出已安装的模块;和pip freeze类似

[root@localhost pip-9.0.1]# pip list –format=legacy
decorator (4.0.11)
ipython (6.1.0)
ipython-genutils (0.2.0)
pexpect (4.2.1)
pip (9.0.1)
ptyprocess (0.5.2)
Pygments (2.2.0)
setuptools (28.8.0)
six (1.10.0)
traitlets (4.3.2)

[root@localhost pip-9.0.1]# pip list –format=columns
Package          Version
—————- ——-
decorator        4.0.11
ipython          6.1.0 
ipython-genutils 0.2.0 
pexpect          4.2.1 
pip              9.0.1 
ptyprocess      0.5.2 
Pygments        2.2.0 
setuptools      28.8.0
six              1.10.0
traitlets        4.3.2

pip show Package:显示已安装的模块信息

[root@localhost pip-9.0.1]# pip show traitlets
Name: traitlets
Version: 4.3.2
Summary: Traitlets Python config system
Home-page: http://ipython.org
Author: IPython Development Team
Author-email: ipython-dev@scipy.org
License: BSD
Location: /usr/local/lib/python3.6/site-packages
Requires: ipython-genutils, six, decorator

pip -h:余下的选项可以通过-h查看,这里不做过多介绍

[root@localhost pip-9.0.1]# pip -h

Usage: 
  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.
  check                      Verify installed packages have compatible dependencies.
  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. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
  –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, (a)bort.
  –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.

本文永久更新链接地址:https://www.linuxidc.com/Linux/2019-02/157062.htm

赞(0) 打赏
转载请注明出处:服务器评测 » CentOS 7下Python 3安装pip-9.0.1
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏