要在使用 python -m pip install -r requirements.txt
时添加腾讯的镜像源,可以通过 -i
或 --index-url
参数指定镜像源地址。腾讯云的 PyPI 镜像源地址是:
https://mirrors.cloud.tencent.com/pypi/simple
具体命令
将腾讯云的镜像源添加到命令中,如下所示:
python -m pip install -r requirements.txt -i https://mirrors.cloud.tencent.com/pypi/simple
其他方式
如果你不想每次都在命令中指定镜像源,可以通过以下方式永久配置:
1. 配置 pip 的全局镜像源
在用户目录下创建或修改 pip.conf
(Linux/macOS)或 pip.ini
(Windows)文件,添加以下内容:
-
Linux/macOS:
mkdir -p ~/.pip echo "[global] index-url = https://mirrors.cloud.tencent.com/pypi/simple trusted-host = mirrors.cloud.tencent.com" > ~/.pip/pip.conf
-
Windows:
- 打开文件资源管理器,在地址栏输入
%APPDATA%
,回车。 - 在打开的目录中,找到或创建
pip
文件夹。 - 在
pip
文件夹中创建或编辑pip.ini
文件,添加以下内容:[global] index-url = https://mirrors.cloud.tencent.com/pypi/simple trusted-host = mirrors.cloud.tencent.com
- 打开文件资源管理器,在地址栏输入
配置完成后,直接运行 python -m pip install -r requirements.txt
就会默认使用腾讯云的镜像源。
2. 使用环境变量
你也可以通过设置环境变量 PIP_INDEX_URL
来指定镜像源:
export PIP_INDEX_URL=https://mirrors.cloud.tencent.com/pypi/simple
然后运行:
python -m pip install -r requirements.txt
总结
- 临时使用腾讯云镜像源:
python -m pip install -r requirements.txt -i https://mirrors.cloud.tencent.com/pypi/simple
- 永久配置腾讯云镜像源:
- 修改
pip.conf
或pip.ini
文件。 - 或设置环境变量
PIP_INDEX_URL
。
- 修改