我试图从一个私有的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
我想要达到的目标可能吗?如果有,我该怎么做?
我发现使用令牌比使用SSH密钥容易得多。我找不到太多关于这方面的好的文档,所以我主要是通过反复试验找到这个解决方案的。此外,从pip和setuptools安装有一些细微的区别;但这种方法应该对双方都有效。
GitHub(目前,截至2016年8月)没有提供一个简单的方法来获得私有存储库的压缩/压缩包。所以你需要告诉setuptools你指向的是Git存储库:
from setuptools import setup
import os
# Get the deploy key from https://help.github.com/articles/git-automation-with-oauth-tokens/
github_token = os.environ['GITHUB_TOKEN']
setup(
# ...
install_requires='package',
dependency_links = [
'git+https://{github_token}@github.com/user/{package}.git/@{version}#egg={package}-0'
.format(github_token=github_token, package=package, version=master)
]
这里有几点注意事项:
For private repositories, you need to authenticate with GitHub; the simplest way I found is to create an OAuth token, drop that into your environment, and then include it with the URL
You need to include some version number (here is 0) at the end of the link, even if there's isn't any package on PyPI. This has to be a actual number, not a word.
You need to preface with git+ to tell setuptools it's to clone the repository, rather than pointing at a zip / tarball
version can be a branch, a tag, or a commit hash
You need to supply --process-dependency-links if installing from pip
我发现使用令牌比使用SSH密钥容易得多。我找不到太多关于这方面的好的文档,所以我主要是通过反复试验找到这个解决方案的。此外,从pip和setuptools安装有一些细微的区别;但这种方法应该对双方都有效。
GitHub(目前,截至2016年8月)没有提供一个简单的方法来获得私有存储库的压缩/压缩包。所以你需要告诉setuptools你指向的是Git存储库:
from setuptools import setup
import os
# Get the deploy key from https://help.github.com/articles/git-automation-with-oauth-tokens/
github_token = os.environ['GITHUB_TOKEN']
setup(
# ...
install_requires='package',
dependency_links = [
'git+https://{github_token}@github.com/user/{package}.git/@{version}#egg={package}-0'
.format(github_token=github_token, package=package, version=master)
]
这里有几点注意事项:
For private repositories, you need to authenticate with GitHub; the simplest way I found is to create an OAuth token, drop that into your environment, and then include it with the URL
You need to include some version number (here is 0) at the end of the link, even if there's isn't any package on PyPI. This has to be a actual number, not a word.
You need to preface with git+ to tell setuptools it's to clone the repository, rather than pointing at a zip / tarball
version can be a branch, a tag, or a commit hash
You need to supply --process-dependency-links if installing from pip
可以使用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
记住:在pip命令中使用远程地址之前,将git remote -v打印的:字符更改为/字符:
$ 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