python - 如何设置 pip 默认从镜像仓库下载?
问题描述
我被迫从本地镜像 PyPi 存储库下载 python 包。我通过使用-i
and--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_name
或pip search package_name
没有任何其他选项?
最终,我可以尝试制作 .bat 文件,该文件将采用以下 2 个参数:
pip %1 -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com "%2"
但我想知道是否有更“优雅”的方式来做到这一点。
解决方案
在用户或全局级别上使用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
#笔记
--index-url
由pip install使用--index
由pip 搜索使用
推荐阅读
- docker - windows 7 docker虚拟盒连接问题
- r - 如何在R中按多个时间范围过滤?
- c# - 将单个 .xaml 文件添加到解决方案时,VSTO 外接程序不再编译
- typescript - Typescript 中展开运算符的属性选择
- azure-devops - 根据计划将不同的参数值传递给 Azure DevOps Pipeline
- mysql - 按订单类型过滤产品
- postgresql - 每个语句插入前的 PostgreSQL 触发器
- date - 昨天的日期在颤抖
- javascript - 在 django 模板中的 js 的 Swiper 功能中创建了重复的元素(产品)
- python - 试图从 pyodbc.drivers() 获取列表,但它什么也没产生,为什么?