在使用pip 安装第三方模块的时候,报错:

WARNING: The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '-trusted-host mirrors.aliyun.com".

翻译成中文大意为:

警告:存储库位于阿里云镜像不是受信任或安全的主机,正在被忽略。如果此存储库可通过HTTPS访问,我们建议您改用HTTPS,否则您可以忽视告警并使用"-trusted-host mirrors.aliyun.com"。

遇到这种情况可以使用 pip -v config list 命令先检查下配置:

(venv) PS D:\pythonProject\MyTools> pip -v config list
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\Administrator\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\Administrator\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'D:\pythonProject\MyTools\venv\pip.ini'

从返回信息可以看到有四条信息,我们建议在最后一条信息的环境(虚拟环境)下编辑或者添加一个pip.ini文件。
添加的内容为:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

然后保存为pip.ini文件,最后再 pip -v config list 确认下结果,我们可以看到结果为:
pip安装问题.png
此刻再安装第三方模块就可以正常使用了。