是否可以使用 pip 从私有 GitHub 存储库安装包?

新手上路,请多包涵

我正在尝试从私有 GitHub 存储库安装 Python 包。对于公共存储库,我可以发出以下运行良好的命令:

 pip install git+git://github.com/django/django.git

但是,如果我尝试将其用于私有存储库:

 pip install git+git://github.com/echweb/echweb-utils.git

我得到以下输出:

 Downloading/unpacking git+git://github.com/echweb/echweb-utils.git
Cloning Git repository git://github.com/echweb/echweb-utils.git to /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build
Complete output from command /usr/local/bin/git clone git://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build:
fatal: The remote end hung up unexpectedly

Cloning into /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build...

----------------------------------------
Command /usr/local/bin/git clone git://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build failed with error code 128

我想这是因为我试图在不提供任何身份验证的情况下访问私有存储库。因此,我尝试使用 Git + ssh 希望 pip 使用我的 SSH 公钥进行身份验证:

 pip install git+ssh://github.com/echweb/echweb-utils.git

这给出了以下输出:

 Downloading/unpacking git+ssh://github.com/echweb/echweb-utils.git
Cloning Git repository ssh://github.com/echweb/echweb-utils.git to /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build
Complete output from command /usr/local/bin/git clone ssh://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build:
Cloning into /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build...

Permission denied (publickey).

fatal: The remote end hung up unexpectedly

----------------------------------------
Command /usr/local/bin/git clone ssh://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build failed with error code 128

我正在努力实现的目标是可能的吗?如果是这样,我该怎么做?

原文由 Adam J. Forster 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 533
2 个回答

您可以使用 git+ssh URI 方案,但您 必须 设置用户名。请注意 URI 中的 git@ 部分:

 pip install git+ssh://git@github.com/echweb/echweb-utils.git

另请阅读 部署密钥

PS:在我的安装中,“git+ssh”URI 方案仅适用于“可编辑”要求:

 pip install -e URI#egg=EggName

Remember : Change the : character that git remote -v prints to a / character before using the remote’s address in the pip command:

 $ git remote -v
origin  git@github.com:echweb/echweb-utils.git (fetch)
#                     ^ change this to a '/' character

如果你忘记了,你会得到这个错误:

 ssh: Could not resolve hostname github.com:echweb:
         nodename nor servname provided, or not known

原文由 oxyum 发布,翻译遵循 CC BY-SA 4.0 许可协议

作为一项附加技术,如果您在本地克隆了私有存储库,则可以执行以下操作:

 pip install git+file://c:/repo/directory

更现代地说,你可以这样做( -e 意味着你不必在反映之前提交更改):

 pip install -e C:\repo\directory

原文由 Scott Stafford 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题