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

为何通过pipenv安装带egg片段的Git源模块时,明明存在依赖仍失败?

问题背景

Windows 10 系统下,使用 Python 3.9.5 版本的 pipenv 执行以下安装命令时出现报错:
pipenv install git+https://github.com/John-Polo/cocoapi.git#egg=PythonAPI

仓库目录结构
cocoapi/PythonAPI/pycocotools
                -/setup.py
                -[更多目录]
完整报错信息
(test-jpGYXydt) C:\Users\john\Documents\code\test>pipenv install git+https://github.com/John-Polo/cocoapi.git#egg=foo
Installing git+https://github.com/John-Polo/cocoapi.git#egg=foo...
Error:  An error occurred while installing git+https://github.com/John-Polo/cocoapi.git#egg=foo!
Error text: Collecting foo
  Cloning https://github.com/John-Polo/cocoapi.git to c:\users\john\appdata\local\temp\pip-install-9ocvuaci\foo_47404cbbe883400593b4786c6adbe805
  Resolved https://github.com/John-Polo/cocoapi.git to commit 2929bd2ef6b451054755dfd7ceb09278f935f7ad

  Running command git clone -q https://github.com/John-Polo/cocoapi.git 'C:\Users\john\AppData\Local\Temp\pip-install-9ocvuaci\foo_47404cbbe883400593b4786c6adbe805'
ERROR: File "setup.py" not found for legacy project foo from git+https://github.com/John-Polo/cocoapi.git#egg=foo (from -r c:\users\john\appdata\local\temp\pipenv-qmfhwbjb-requirements\pipenv-2bqximai-requirement.txt (line 1)).

Installation Failed
错误原因

pipenv 底层调用的 pip 逻辑默认从 Git 仓库的根目录查找 setup.py、pyproject.toml 等包配置文件,你的 setup.py 存放在 PythonAPI 子目录下,不在仓库根目录,因此安装程序无法识别到该文件。

修复方案

有两种可行修复方案:

  • 方案一:调整文件位置。将 setup.py 及配套的包安装所需文件从 PythonAPI 子目录移动到仓库根目录,即可解决找不到 setup.py 的问题,该方案已验证有效。
  • 方案二:指定子目录安装。无需修改仓库结构,直接在安装命令中添加 subdirectory 参数指定配置文件所在的子目录即可,命令如下:
    pipenv install git+https://github.com/John-Polo/cocoapi.git#subdirectory=PythonAPI&egg=PythonAPI

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 00:45:00