You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Poetry安装含私有依赖模块失败,构建时找不到module_b求助

解决Poetry构建时无法获取私有仓库间接依赖的问题

问题分析

你遇到的核心问题是:Poetry能从私有Nexus仓库下载直接依赖module_a,但在构建module_a过程中,无法找到同仓库中的间接依赖module_b。原因在于Poetry默认不会将私有源信息传递给构建阶段调用的pip,导致pip仅从PyPI查找module_b;而pip通过--extra-index-url可以全局应用额外源,因此能正常处理这类依赖。

解决方案

1. 升级Poetry到最新版本

旧版本Poetry在私有源处理、构建依赖传递上存在兼容性问题,先升级到稳定版:

poetry self update

2. 调整私有源优先级(推荐)

将私有仓库设为默认源,让Poetry优先从私有仓库查找所有依赖(包括间接依赖),PyPI作为备用源:
修改pyproject.toml中的源配置:

[[tool.poetry.source]]
name = "nexus"
url = "https://my_nexus_url/private_repo/simple"
default = true  # 设为默认源

[[tool.poetry.source]]
name = "pypi"
url = "https://pypi.org/simple"
secondary = true  # PyPI作为备用源

3. 配置Poetry传递私有源给pip

如果不想修改默认源优先级,可通过配置pip全局额外源,让Poetry调用pip时自动使用私有仓库:
在poetry.toml(项目级)或~/.config/pypoetry/config.toml(全局级)中添加:

[tool.poetry.config]
pip_config = """
[global]
extra-index-url = https://my_nexus_url/private_repo/simple
"""

4. 显式声明间接依赖的源

即使module_b是module_a的间接依赖,也可以在pyproject.toml中显式指定它的源,强制Poetry从私有仓库获取:

[tool.poetry.dependencies]
python = "^3.8"
module_a = { version = "1.0.0", source = "nexus" }
module_b = { version = "1.0.1", source = "nexus" }

验证

修改配置后,清理缓存并重新安装以确保生效:

poetry cache clear --all pypi
poetry cache clear --all nexus
poetry install

内容的提问来源于stack exchange,提问作者theShadow89

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 18:50:41