首页 > 解决方案 > 如何设置 pip 默认从镜像仓库下载?

问题描述

我被迫从本地镜像 PyPi 存储库下载 python 包。我通过使用-iand--trusted-host选项来做到这一点。整个安装命令如下所示:

pip install -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com package_name

不过,每次都必须输入这些选项有点烦人(实际上这些都是长 URL)。我尝试使用以下内容创建 get_package.bat 文件(我正在使用 Windows 10):

pip install -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com "%1"

它工作得很好,虽然当我想执行 pip search 命令时,结果证明它没有用,因为它有硬编码的install命令并且没有办法将它与search.

有什么方法可以设置 pip 默认从镜像存储库下载,这样我就可以执行pip install package_namepip search package_name没有任何其他选项?

最终,我可以尝试制作 .bat 文件,该文件将采用以下 2 个参数:

pip %1 -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com "%2"

但我想知道是否有更“优雅”的方式来做到这一点。

标签: pythonpippypi

解决方案


在用户或全局级别上使用pip config 。我是这样/etc/pip.conf配置的:

[global]
index=https://my-company/nexus/repository/pypi-group/pypi
index-url=https://my-company/nexus/repository/pypi-group/simple
trusted-host=my-company

但是您可以pip config在用户或全局级别上配置它,例如:

pip config --user set global.index https://my-company/nexus/repository/pypi-group/pypi
pip config --user set global.index-url https://my-company/nexus/repository/pypi-group/simple
pip config --user set global.trusted-host my-company

#笔记


推荐阅读