Python pip简介

在Python中,正因为其强大的扩展性,其官方就给他开发了一个第三方库管理工具-----pip。这一章,我会给大家介绍一下这个第三方库管理工具。

1 使用方法

按win+r,输入“cmd”,进入命令行。再输入以下指令:

pip help

2 指令

假如你的Python安装正确,会看到里面的这样一段信息:

Usage:
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  inspect                     Inspect the python environment.
  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.

这是pip的各种指令。常用指令有:

install------安装第三方库

download------下载打包的第三方库

uninstall------卸载第三方库

search------搜索第三方库

执行方法:

pip <指令> <参数>

pip install <安装库名>

pip download <下载库名>

pip uninstall <卸载库名>

pip search <搜索库名>

3 临时换源

在下载或安装过程中,可能会遇到无法下载的情况。这时就要换源。执行如下指令:

pip install <下载库名> -i <源名>

源名有以下几种:

3.1 清华大学

https://pypi.tuna.tsinghua.edu.cn/simple

3.2 阿里云

https://mirrors.aliyun.com/pypi/simple/

3.3 网易

https://mirrors.163.com/pypi/simple/ 

3.4 豆瓣

https://pypi.douban.com/simple/ 

3.5 百度云

https://mirror.baidu.com/pypi/simple/

3.6 中科大

https://pypi.mirrors.ustc.edu.cn/simple/

3.7 华为云

https://mirrors.huaweicloud.com/repository/pypi/simple/

3.8 腾讯云

https://mirrors.cloud.tencent.com/pypi/simple/

我们以清华大学为例:

pip install <下载库名> -i https://pypi.tuna.tsinghua.edu.cn/simple

执行该指令即可实现临时换源。

4 更改默认源

运行以下代码:

pip config set global.index-url <默认源>

在最后加上你需要更改的默认源即可,我个人更推荐于这种方法,因为其不用每次手动输入源。你更喜欢哪一种呢?

  • 30
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值