pip 卸载大法

  1. pip install pip-autoremove
  2. pip-autoremove jupyter

pip 加速(使用代理)

pip 加速(使用镜像)

  • 临时使用镜像,命令行使用参数项-i
  1. pip install 模块名 -i https://pypi.douban.com/simple/
  • 自动配置

    1. pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
  • 手动配置,pip 添加配置文件

查看用户主目录下有没有”~/.pip/pip.conf”文件,没有则创建。

  1. mkdir .pip
  2. touch .pip/pip.conf

打开文件,添加以下配置项

  1. [global]
  2. index-url=http://pypi.douban.com/simple
  3. [install]
  4. trusted-host=pypi.douban.com

可选镜像网址

豆瓣

  1. [global]
  2. index-url=http://pypi.douban.com/simple
  3. [install]
  4. trusted-host=pypi.douban.com

阿里云

  1. [global]
  2. index-url=http://mirrors.aliyun.com/pypi/simple
  3. [install]
  4. trusted-host=mirrors.aliyun.com

清华大学

  1. [global]
  2. index-url=https://pypi.tuna.tsinghua.edu.cn/simple
  3. [install]
  4. trusted-host=pypi.tuna.tsinghua.edu.cn

pip 配置文件

首先检测配置文件是否存在,没有则创建之。配置文件的路径(本用户有效):

  • Unix: $HOME/.config/pip/pip.conf
  • Mac: $HOME/Library/Application Support/pip/pip.conf
  • Windows: %APPDATA%\pip\pip.ini%APPDATA% 的实际路径我电脑上是 C:\Users\user_xxx\AppData\Roaming ,可在 cmd 里执行 echo %APPDATA% 命令查看

virtualenv 和全局的配置文件路径参见 pip文档

配置文件内容如下:

  1. [global]
  2. index-url = http://mirrors.aliyun.com/pypi/simple/ # 这里使用的是阿里云的镜像源
  3. proxy=http://xxx.xxx.xxx.xxx:8080 # 替换出自己的代理地址,格式为[user:passwd@]proxy.server:port
  4. [install]
  5. trusted-host=mirrors.aliyun.com # 信任阿里云的镜像源,否则会有警告

配置文件的原则就是,凡是pip命令行的参数都可以在配置文件里定义其默认值!
至于[global]、[install]等标志我没找到具体说明,估计是配置参数的作用范围。

我的配置

C:\Users\DP\AppData\Roaming\pip\pip.ini

  1. [global]
  2. proxy=http://127.0.0.1:1080