🍖02 不同平台更换pip源

引入

前面介绍过通过 Pycharm 更换 pip 镜像源 : https://www.cnblogs.com/songhaixing/p/14551260.html

一.国内常用镜像源

二.临时使用

  • 可以在使用 pip 的时候,加上参数 -i 和镜像地址
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pymysql

三.不同平台永久修改

1.windows 平台

  • 进入 : C:Users[电脑用户]AppDataRoaming 文件夹中

> 注意 : 有些电脑找不到 AppData 目录, 这是因为隐藏了, 点击左上角 "查看", 勾选右边的 "隐藏项目" 可进行查看 :

image-20210502194632127

  • 新建 pip 文件夹并在文件夹中新建 pip.ini 配置文件
  • 新增 pip.ini 配置文件内容 (以清华源为例) :
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
[install]
use-mirrors=true
mirrors=https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host=pypi.tuna.tsinghua.edu.cn

2.MacOS、Linux 平台

  • 在用户根目录下 ~(家)目录 下创建 .pip 隐藏文件夹, 如果已经有了可以跳过
mkdir ~/.pip
  • 进入 .pip 隐藏文件夹并创建 pip.conf 配置文件
cd ~/.pip
touch pip.conf
  • 输入配置文件内容(以清华源为例)
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
[install]
use-mirrors=true
mirrors=https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host=pypi.tuna.tsinghua.edu.cn

四.导出安装项目依赖包

1.导出项目中使用的所有依赖包 (用于项目移植,拷贝等)

pip3 freeze > requirements.txt  # 后面的文件名可以自定义

2.从文件中一键安装项目中使用到的所有依赖包

pip3 install -r requirement.txt
原文地址:https://www.cnblogs.com/songhaixing/p/14730586.html