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

pip安装私有Python包时报'-e git+h'解析错误该如何解决?

报错原因
  • setuptools 的 install_requires 字段仅支持符合 PEP 508 规范的依赖声明,不识别 -e 开头的可编辑安装标识。之前可正常运行是因为旧版本 setuptools 对依赖格式校验宽松,升级到高版本后校验规则收紧,直接触发解析错误。
  • 你当前的代码直接将 requirements.txt 全量内容读取到 install_requires 中,包含不符合规范的 -e git+xxx 格式行,所以解析失败。
解决方案

方案1:修改依赖声明为PEP 508兼容格式(最推荐)

直接修改 requirements.txt 中的 zempy 依赖行,去掉 -e 标识,用 @ 关联 Git 地址即可,无需修改 setup.py 代码:

zempy @ git+https://gitlab.com/group/zempy.git@0.4.7

修改后直接执行安装命令即可正常拉取对应版本的私有依赖。

方案2:保留可编辑安装需求的处理方式

如果需要保留 zempy 的可编辑安装模式,按以下步骤操作:

  1. 保留 requirements.txt 中的 -e git+https://gitlab.com/group/zempy.git@0.4.7#egg=zempy 行
  2. 修改 setup.py 中的 get_requirements 函数,过滤掉非法格式的行:
def get_requirements():
    """
    Return requirements as list.
    """
    with open('requirements.txt') as f:
        req_list = []
        for line in f.readlines():
            line = line.strip()
            # 过滤空行、注释行、-e开头的可编辑依赖行
            if not line or line.startswith("#") or line.startswith("-e"):
                continue
            req_list.append(line)
        return req_list
  1. 安装 hidden 包前,先单独安装 zempy:
python3 -m pip install -e git+https://gitlab.com/group/zempy.git@0.4.7#egg=zempy
  1. 再执行 python3 -m pip install . 或 python3 -m pip install -e . 安装 hidden 包即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.27 23:45:04