Python3 PIP 安装


pip is the package installer for Python. You can use it to install packages from the Python Package Index and other indexes.

——pip.pypa.io

鲁迅先生曾经说过这样一句话:“没有pip的Python是没有灵魂的(是不是有点过了)。”

但是,很多人在使用pip的时候,或多或少会遇到这种情况:

[xiaodeng@xd-pc ~]$ python3 -m pip
/usr/bin/python3: No module named pip

如果你遇到了这个提示,那么恭喜你,你 的 Python 没 装 pip!

其实,这种情况很好解决,但是我曾经也被整的晕头转向,话不多说,上解决方案!

解决方案

通用

  1. 下载https://bootstrap.pypa.io/get-pip.py;
  2. 执行

Linux

可以吧这一段代码复制到终端执行:

wget https://bootstrap.pypa.io/get-pip.py
python3 ./get-pip.py
rm ./get-pip.py

输出(因人而异):

[xiaodeng@xd-pc ~]$ wget https://bootstrap.pypa.io/get-pip.py
--2021-12-11 15:07:06--  https://bootstrap.pypa.io/get-pip.py
SSL_INIT
已载入 CA 证书“/etc/ssl/certs/ca-certificates.crt”
正在解析主机 bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.76.175, 2a04:4e42:12::175
正在连接 bootstrap.pypa.io (bootstrap.pypa.io)|151.101.76.175|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2159352 (2.1M) [text/x-python]
正在保存至: “get-pip.py”

get-pip.py          100%[===================>]   2.06M  3.34MB/s  用时 0.6s    

2021-12-11 15:07:07 (3.34 MB/s) - 已保存 “get-pip.py” [2159352/2159352])

[xiaodeng@xd-pc ~]$ python3 ./get-pip.py
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 1.7 MB/s            
Collecting wheel
  Downloading wheel-0.37.0-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel, pip
Successfully installed pip-21.3.1 wheel-0.37.0
[xiaodeng@xd-pc ~]$ rm ./get-pip.py
[xiaodeng@xd-pc ~]$ 

验证安装

[xiaodeng@xd-pc ~]$ python3 -m pip

Usage:   
  /usr/bin/python3 -m 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.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  cache                       Inspect and manage pip's wheel cache.
  index                       Inspect information available from package indexes.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --debug                     Let unhandled exceptions propagate outside the
                              main subroutine, instead of logging them to
                              stderr.
  --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.
  --no-input                  Disable prompting for input.
  --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 or host:port pair as trusted,
                              even though it does not have valid or any HTTPS.
  --cert <path>               Path to PEM-encoded CA certificate bundle. If
                              provided, overrides the default. See 'SSL
                              Certificate Verification' in pip documentation
                              for more information.
  --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.
  --no-color                  Suppress colored output.
  --no-python-version-warning
                              Silence deprecation warnings for upcoming
                              unsupported Pythons.
  --use-feature <feature>     Enable new functionality, that may be backward
                              incompatible.
  --use-deprecated <feature>  Enable deprecated functionality, that will be
                              removed in the future.
[xiaodeng@xd-pc ~]$