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

如何从GitHub私有仓库安装setup.py不在根目录的Python包?

无需移动setup.py安装GitHub仓库的正确方法

直接使用pip的subdirectory参数指定setup.py所在的子目录即可,同时保留#egg=参数指定包名,命令格式如下:

pip install git+https://github.com/你的用户名/components_repo.git#subdirectory=src#egg=components-package
  • #subdirectory=src:告诉pip去仓库的src目录下寻找setup.py文件
  • #egg=components-package:指定包的名称,这是从GitHub仓库安装Python包时的必填项,避免pip抛出"需指定包名"的错误

如果是私有仓库,改用SSH地址即可:

pip install git+ssh://git@github.com/你的用户名/components_repo.git#subdirectory=src#egg=components-package

执行这个命令后,repo_1和repo_2就能正常引用components_repo的组件,无需移动setup.py文件或修改路径。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 08:15:43