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

pip安装Bitbucket私有Python包时未自动装依赖,需如何修改包配置?

解决Hatchling构建包时依赖未自动安装的问题

当你用pip install git+<仓库地址>安装包时,Hatchling(遵循PEP 621规范)不会自动读取requirements.txt里的依赖配置——现代Python打包工具默认以pyproject.toml作为依赖声明的权威来源,而非传统的requirements.txt。

你需要做以下修改:

1. 将依赖写入pyproject.toml的[project]区块

打开项目根目录的pyproject.toml,找到[project]部分,添加dependencies字段,把requirements.txt里的所有依赖迁移进去。示例如下:

[project]
name = "你的包名"
version = "0.1.0"
# 保留你已有的其他配置
dependencies = [
    "requests>=2.25.1",
    "numpy>=1.21.0",
    # 把requirements.txt里的所有依赖按格式添加到这里
]

2. 开发依赖单独配置(可选)

如果requirements.txt里包含测试、代码格式化这类仅开发时需要的依赖,不要放到主dependencies里,而是添加到[project.optional-dependencies]的dev子项中:

[project.optional-dependencies]
dev = [
    "pytest>=7.0",
    "black>=22.0"
]

后续需要安装开发依赖时,可执行:

(venv) $ pip install git+https://bitbucket.company.com/path/to/package.git[dev]

3. 验证修改效果

修改完成后,重新执行你的安装命令:

(venv) $ pip install git+https://bitbucket.company.com/path/to/package.git

此时pip会自动读取pyproject.toml里声明的依赖并完成安装。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 00:47:18