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

小型Python项目执行poetry update耗时3小时,问题出在哪?

解决Poetry本地路径依赖开发模式不生效+依赖解析过慢问题

一、本地依赖未启用开发模式(核心问题)

你当前的pyproject.toml只是配置了本地路径依赖,但没开启Poetry的开发模式,导致Poetry会把crawler的代码复制到虚拟环境而非创建符号链接,所以修改crawler后无法实时同步,必须升级版本触发重新复制。

正确的配置方式是在crawler-tester的pyproject.toml里给crawler依赖加上develop = true:

[tool.poetry.dependencies]
python = "^3.10"
crawler = { path = "../crawler", develop = true }

配置完成后,执行poetry install重新安装依赖,此时Poetry会在虚拟环境中创建crawler的符号链接,后续修改crawler的代码会直接同步到crawler-tester的运行环境,不用再升级版本或执行update。

二、依赖解析耗时过慢的解决方法

  1. 锁定crawler的依赖版本
    在crawler项目根目录执行poetry lock生成poetry.lock文件,这样crawler-tester在解析依赖时会直接复用crawler已锁定的依赖版本,避免重复遍历所有可能的版本组合。

  2. 指定外部依赖的版本范围
    给azure-identity、azure-core、boto3这类外部依赖明确版本范围,比如:

    # crawler项目的pyproject.toml
    [tool.poetry.dependencies]
    python = "^3.10"
    azure-identity = "^1.12.0"
    azure-core = "^1.29.0"
    boto3 = "^1.28.0"
    

    模糊的版本范围会让Poetry花费大量时间计算兼容组合,明确范围能大幅缩短解析时间。

  3. 避免全量poetry update
    全量update会强制Poetry重新解析所有依赖的最新版本,耗时极长。如果只是同步crawler的修改,执行poetry install即可;如果确实需要更新依赖,指定具体包名,比如poetry update crawler,只更新目标包。

三、常见操作误区

不要用poetry update来同步本地依赖的修改,update的作用是升级依赖版本,而同步配置或本地依赖变更应该用poetry install。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 03:35:09