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

安装本地Python包时如何同时安装其传递依赖?

如何同时安装本地依赖包及其自身依赖?

当然可以,有两种简单的实现方式:

方式一:在requirements.txt中嵌套依赖文件

直接修改batch/lol_integration/requirements.txt,把lol-pandas的依赖文件和本地包路径都加进去:

-r ../../libs/lol-pandas/requirements.txt
../../libs/lol-pandas/

执行pip install -r requirements.txt时,pip会先安装lol-pandas的requirements.txt里的所有依赖,再安装lol-pandas本地包。

方式二:通过pyproject.toml声明依赖(推荐)

如果你的lol-pandas项目用了现代Python构建工具(比如setuptools、Poetry),更规范的做法是把它的依赖写到libs/lol-pandas/pyproject.toml的[project.dependencies]区块里,比如:

[project]
name = "lol-pandas"
# 其他项目配置...

[project.dependencies]
pandas = ">=2.0.0"
# 把原requirements.txt里的依赖都移到这里

这样当你通过../../libs/lol-pandas/安装lol-pandas时,pip会自动识别并安装pyproject.toml中声明的所有依赖,不需要额外修改lol-integration的requirements.txt。

为什么原来的方式不行?

你之前只写了本地包路径,pip只会安装lol-pandas包本身,不会主动去读取它的requirements.txt文件——这个文件是给开发者手动安装依赖用的,不是pip安装包时的默认依赖来源。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 05:42:21