pip换源及指令的使用

Posted BkbK-

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pip换源及指令的使用相关的知识,希望对你有一定的参考价值。

pip换源及指令的使用

一、pip换源命令

pip国内的一些镜像源:

1.临时使用:

pip的时候在后面加上-i参数,指定pip源

pip install SomePackage -i http://mirrors.aliyun.com/pypi/simple/
pip install SomePackage -i https://pypi.tuna.tsinghua.edu.cn/simple/ 
pip install SomePackage -i http://pypi.mirrors.ustc.edu.cn/simple/

2.永久修改

(1)Linux:

修改 ~/.pip/pip.conf (没有就创建一个), 内容如下:

[global]
index-url = [国内镜像源链接]

如:

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/ 
[global]
index-url = http://pypi.mirrors.ustc.edu.cn/simple/

(2)Windows

win+R 打开用户目录%HOMEPATH%,在此目录下创建 pip 文件夹,在 pip 目录下创建 pip.ini 文件, 内容如下

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

二、pip指令的使用

pip(Python Package Index)是一个以 Python 语言写成的软件包管理系統,使用 pip 可以非常方便的安装和管理 python 软件包。

执行 pip --help 命令,可以看到如下所示的帮助文档

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.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  cache                       Inspect and manage pip’s wheel cache.
  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.
  --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 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.
  --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.

使用时,输入pip <command> [options] 形式的指令,即可执行相应的命令,并且,command 和 options 可以任意组合,如果遇到不太会用的 command,可以使用 --help 选项调出帮助文档。

以上是关于pip换源及指令的使用的主要内容,如果未能解决你的问题,请参考以下文章

pip国内常用源及配置方式

国内pip源及pip命令

windows pip换源,python 换源

pip 常用镜像源及永久配置镜像源

pip换源

Mac下conda换源、pip换源