Ada*_*ter 321 python git pip github
正如标题所示,我试图从私有github仓库安装一个python包.对于公共存储库,我可以发出以下命令,该命令工作正常:
pip install git+git://github.com/django/django.git
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试使用私有存储库:
pip install git+git://github.com/echweb/echweb-utils.git
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
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
Run Code Online (Sandbox Code Playgroud)
我想这是因为我试图访问私有存储库而不提供任何身份验证.因此我尝试使用git + ssh希望pip使用我的ssh公钥进行身份验证:
pip install git+ssh://github.com/echweb/echweb-utils.git
Run Code Online (Sandbox Code Playgroud)
这给出了以下输出:
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
Run Code Online (Sandbox Code Playgroud)
有谁知道我想要达到的目标是否可能?如果是这样,请告诉我怎么样?
oxy*_*yum 329
你可以使用git+sshURI方案,但你必须设置用户名:
pip install git+ssh://git@github.com/echweb/echweb-utils.git
Run Code Online (Sandbox Code Playgroud)
请参阅git@URI部分?
PS:还阅读有关部署密钥的信息.
PPS:在我的安装中,"git + ssh"URI方案仅适用于"可编辑"要求:
pip install -e URI#egg=EggName
Run Code Online (Sandbox Code Playgroud)
切记:在命令中使用远程地址之前:,将git remote -v打印的/字符更改为字符pip:
$ git remote -v
origin git@github.com:echweb/echweb-utils.git (fetch)
^ change this to a '/' character
Run Code Online (Sandbox Code Playgroud)
如果您忘记了,您将收到此错误:
ssh: Could not resolve hostname github.com:echweb:
nodename nor servname provided, or not known
Run Code Online (Sandbox Code Playgroud)
Sco*_*ord 69
作为一种额外的技术,如果您在本地克隆了私有存储库,则可以执行以下操作:
pip install git+file://c:/repo/directory
Run Code Online (Sandbox Code Playgroud)
编辑:更现代化,你可以这样做(这-e意味着你不必在反映之前提交更改):
pip install -e C:\repo\directory
Run Code Online (Sandbox Code Playgroud)
dan*_*ius 46
您可以使用HTTPS URL直接执行此操作,如下所示:
pip install git+https://github.com/username/repo.git
Run Code Online (Sandbox Code Playgroud)
例如,这也可以在django项目中的requirements.txt中附加该行.
小智 26
也适用于Bitbucket:
pip install git+ssh://git@bitbucket.org/username/projectname.git
Run Code Online (Sandbox Code Playgroud)
在这种情况下,Pip将使用您的SSH密钥.
pck*_*ko1 19
我的情况比答案中描述的大多数情况都要复杂一些。repo_A我是两个私有存储库和一个 Github 组织的所有者repo_B,并且需要pip install repo_A在python单元测试repo_B期间作为 Github 操作。
我为解决此任务而遵循的步骤:
repo_B,将我的个人访问令牌粘贴到其中并命名PERSONAL_ACCESS_TOKEN。这很重要,因为与Jamie提出的解决方案不同,我不需要在 github 操作.yml文件中显式公开我宝贵的原始个人访问令牌。pip installSSH)从源进行打包,如下所示:export PERSONAL_ACCESS_TOKEN=${{ secrets.PERSONAL_ACCESS_TOKEN }}
pip install git+https://${PERSONAL_ACCESS_TOKEN}@github.com/MY_ORG_NAME/repo_A.git
Run Code Online (Sandbox Code Playgroud)
Ami*_*ein 16
如果要从CI服务器或类似服务器中的需求文件安装依赖项,可以执行以下操作:
git config --global credential.helper 'cache'
echo "protocol=https
host=example.com
username=${GIT_USER}
password=${GIT_PASS}
" | git credential approve
pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
就我而言,我使用了GIT_USER=gitlab-ci-token和GIT_PASS=${CI_JOB_TOKEN}。
这种方法有明显的优势。您有一个包含所有依赖项的需求文件。
Rac*_*hel 14
需求文件的语法如下:
https://pip.pypa.io/en/latest/reference/pip_install.html#requirements-file-format
例如:
-e git+http://github.com/rwillmer/django-behave#egg=django-behave
Run Code Online (Sandbox Code Playgroud)
如果您希望源安装后留下来
要不就
git+http://github.com/rwillmer/django-behave#egg=django-behave
Run Code Online (Sandbox Code Playgroud)
如果你只是想安装它.
JS.*_*JS. 14
我想出了一种自动"pip安装"GitLab私有存储库的方法,该存储库不需要密码提示.此方法使用GitLab"Deploy Keys"和SSH配置文件,因此您可以使用除个人SSH密钥之外的密钥进行部署(在我的情况下,供'bot使用).也许某个善良的灵魂可以使用GitHub进行验证.
ssh-keygen -t rsa -C "GitLab_Robot_Deploy_Key"
该文件应显示为~/.ssh/GitLab_Robot_Deploy_Key和~/.ssh/GitLab_Robot_Deploy_Key.pub
将~/.ssh/GitLab_Robot_Deploy_Key.pub文件内容复制并粘贴到GitLab"Deploy Keys"对话框中.
以下命令告诉SSH使用新的部署密钥来设置连接.成功之后,您应该收到消息:"欢迎使用GitLab,UserName!"
ssh -T -i ~/.ssh/GitLab_Robot_Deploy_Key git@gitlab.mycorp.com
接下来,使用编辑器创建~/.ssh/config文件.添加以下内容."主机"值可以是您想要的任何值(只需记住它,因为您稍后将使用它).HostName是GitLab实例的URL.IdentifyFile是您在第一步中创建的SSH密钥文件的路径.
Host GitLab
HostName gitlab.mycorp.com
IdentityFile ~/.ssh/GitLab_Robot_Deploy_Key
Run Code Online (Sandbox Code Playgroud)
@oxyum给了我们使用SSH与pip的方法:
pip install git+ssh://git@gitlab.mycorp.com/my_name/my_repo.git
我们只需要稍微修改它以使SSH使用我们新的Deploy Key.我们通过将SSH指向SSH配置文件中的Host条目来实现.只需将命令中的'gitlab.mycorp.com'替换为我们在SSH配置文件中使用的主机名:
pip install git+ssh://git@GitLab/my_name/my_repo.git
该软件包现在应该安装时没有密码提示.
Max*_*ian 13
我发现使用令牌比使用SSH密钥要容易得多.我找不到很多关于此的好文档,所以主要通过反复试验来解决这个问题.此外,从pip和setuptools安装有一些细微的差别; 但这种方式应该适用于两者.
GitHub没有(目前,截至2016年8月)提供了一个简单的方法来获取私人回购的zip/tarball.所以你需要指向setuptools告诉setuptools你指向一个git repo:
from setuptools import setup
import os
# get 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)
]
Run Code Online (Sandbox Code Playgroud)
这里有几点说明:
0),即使PyPI上没有包.这必须是实际数字,而不是单词.git+中告诉setuptools克隆repo,而不是指向zip/tarballversion 可以是分支,标记或提交哈希--process-dependency-links如果从pip安装,你需要提供如果您需要在命令行单行程序中执行此操作,也可以这样做。我能够在 Google Colab 上进行部署:
pip install git+https://<PERSONAL ACCESS TOKEN>@github.com/<USERNAME>/<REPOSITORY>.git小智 8
如果不想使用 SSH,可以在 HTTPS URL 中添加用户名和密码。
下面的代码假设您在工作目录中有一个名为“pass”的文件,其中包含您的密码。
export PASS=$(cat pass)
pip install git+https://<username>:$PASS@github.com/echweb/echweb-utils.git
Run Code Online (Sandbox Code Playgroud)
当我从github安装时,我能够使用:
pip install git+ssh://git@github.com/<username>/<projectname>.git#egg=<eggname>
Run Code Online (Sandbox Code Playgroud)
但是,因为我还得跑PIP作为sudo,SSH密钥没有用github上工作了,"混帐克隆"的"权限被拒绝(公钥)"失败.使用git+https允许我以sudo运行命令,并让github问我我的用户/密码.
sudo pip install git+https://github.com/<username>/<projectname>.git#egg=<eggname>
Run Code Online (Sandbox Code Playgroud)
您还可以通过git + https://github.com/... URL 安装私有repo依赖项,方法是为文件提供curl的登录凭据(登录名和密码或部署令牌).netrc:
echo "machine github.com login ei-grad password mypasswordshouldbehere" > ~/.netrc
pip install "git+https://github.com/ei-grad/my_private_repo.git#egg=my_private_repo"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
190243 次 |
| 最近记录: |