目录
  1. 一、更换国内源
    1. 1、国内主要源列表
    2. 2、临时使用
    3. 3、永久修改
      1. 3.1、linux
      2. 3.2、windows
  2. 二、基本用法
    1. 1、查找库
    2. 2、查看所有已安装库
      1. 2.1、全部显示
      2. 2.2、只显示可升级的库
    3. 3、查看指定的已安装库
    4. 4、安装
      1. 4.1、标准安装
      2. 4.2、指定版本安装
      3. 4.3、升级安装
    5. 5、卸载库
  3. 三、高级用法
    1. 1、 pip-review 更新所有库
    2. 2、缓存管理
    3. 3、使用 requirements.txt 批量安装
      1. 3.1、生成 requirements.txt 文件
      2. 3.2、执行 requirements.txt 文件
    4. 4、从git上安装库
      1. 4.1、 标准安装
      2. 4.2、 分支安装
【配置】pip更换国内源的方法

欢迎访问的个人博客,博客地址为 https://haibei.online/

一、更换国内源

1、国内主要源列表

来源地址
华为https://mirrors.huaweicloud.com/repository/pypi/simple
清华https://pypi.tuna.tsinghua.edu.cn/simple
阿里云http://mirrors.aliyun.com/pypi/simple/
中国科技大学https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学http://pypi.hustunique.com/
山东理工大学http://pypi.sdutlinux.org/
豆瓣http://pypi.douban.com/simple/

2、临时使用

可以在使用pip的时候在后面加上-i参数,指定pip源
以安装scrapy为例

1
pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple

3、永久修改

3.1、linux

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

1
2
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

3.2、windows

直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下

1
2
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

二、基本用法

1、查找库

1
pip search pytorch

2、查看所有已安装库

2.1、全部显示

1
pip list

2.2、只显示可升级的库

1
pip list --outdated

3、查看指定的已安装库

1
pip show pytorch

4、安装

4.1、标准安装

1
pip install pytorch

4.2、指定版本安装

1
pip install pytorch==1.2.0

4.3、升级安装

1
pip install -U pytorch

5、卸载库

1
pip uninstall pytorch

三、高级用法

1、 pip-review 更新所有库

1
pip install pip-review
  • 自动批量升级
1
pip-review --auto
  • 以交互方式升级
1
pip-review --interactive

2、缓存管理

  • 无缓存安装
1
pip install pytorch --no-cache-dir
  • 直接清除缓存
    • Linux and Unix: ~/.cache/pip
    • OS X: ~/Library/Caches/pip
    • Windows: %LocalAppData%\pip\Cache

3、使用 requirements.txt 批量安装

requirements.txt 用于记录当前项目中的所有依赖包及其精确的版本号,可以方便地进行快速部署。

3.1、生成 requirements.txt 文件

1
pip freeze >requirements.txt

3.2、执行 requirements.txt 文件

1
pip install -r requirements.txt

4、从git上安装库

4.1、 标准安装

1
pip install git+https://github.com/pytorch/pytorch.git

4.2、 分支安装

1
pip install git+https://github.com/pytorch/pytorch.git@master
文章作者: Haibei
文章链接: http://www.haibei.online/posts/277300404.html
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Haibei的博客
打赏
  • 微信
  • 支付宝

评论