是否可以使用 pip 从私有 GitHub 存储库安装包? [英] Is it possible to use pip to install a package from a private GitHub repository?
问题描述
我正在尝试从私有 GitHub 存储库安装 Python 包.对于公共存储库,我可以发出以下可以正常工作的命令:
I am trying to install a Python package from a private GitHub repository. For a public repository, I can issue the following command which works fine:
pip install git+git://github.com/django/django.git
但是,如果我为私有存储库尝试此操作:
However, if I try this for a private repository:
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 公钥进行身份验证:
I guess this is because I am trying to access a private repository without providing any authentication. I therefore tried to use Git + ssh
hoping that pip would use my SSH public key to authenticate:
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
我正在努力实现的目标是否可能?如果是这样,我该怎么做?
Is what I am trying to achieve even possible? If so, how can I do it?
推荐答案
您可以使用 git+ssh
URI 方案,但您必须设置用户名.注意 URI 中的 git@
部分:
You can use the git+ssh
URI scheme, but you must set a username. Notice the git@
part in the URI:
pip install git+ssh://git@github.com/echweb/echweb-utils.git
另请阅读部署密钥.
PS:在我的安装中,git+ssh"URI 方案仅适用于可编辑"要求:
PS: In my installation, the "git+ssh" URI scheme works only with "editable" requirements:
pip install -e URI#egg=EggName
记住:在使用之前,将 git remote -v
打印的 :
字符更改为 /
字符pip
命令中的远程地址:
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
如果你忘记了,你会得到这个错误:
If you forget, you will get this error:
ssh: Could not resolve hostname github.com:echweb:
nodename nor servname provided, or not known
这篇关于是否可以使用 pip 从私有 GitHub 存储库安装包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!