Python 从 git repo 分支安装 pip

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20101834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 19:31:31  来源:igfitidea点击:

pip install from git repo branch

pythongitpip

提问by goh

Trying to pipinstall a repo's specific branch. Google tells me to

尝试pip安装 repo 的特定分支。谷歌告诉我

pip install git+https://github.com/user/repo.git@branch

pip 安装 git+ https://github.com/user/repo.git@branch

The branch's name is issue/34/oscar-0.6so I did pip install https://github.com/tangentlabs/django-oscar-paypal.git@/issue/34/oscar-0.6but its returning a 404.

分支的名称是issue/34/oscar-0.6我所做的,pip install https://github.com/tangentlabs/django-oscar-paypal.git@/issue/34/oscar-0.6但它返回了 404。

How do I install this branch?

我如何安装这个分支?

采纳答案by falsetru

Prepend the url prefix git+(See VCS Support):

前置 url 前缀git+(请参阅VCS 支持):

pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6

And specify the branch name without the leading /.

并指定不带前导的分支名称/

回答by Steve K

Using pip with git+ to clone a repository can be extremely slow (test with https://github.com/django/django@stable/1.6.xfor example, it will take a few minutes). The fastest thing I've found, which works with GitHub and BitBucket, is:

使用 pip 和 git+ 克隆存储库可能非常慢(例如,使用https://github.com/django/django@stable/1.6.x进行测试,这将需要几分钟)。我发现的最快的东西,它适用于 GitHub 和 BitBucket,是:

pip install https://github.com/user/repository/archive/branch.zip

which becomes for django master:

对于 django 大师来说,这变成了:

pip install https://github.com/django/django/archive/master.zip

for django stable/1.7.x:

对于 Django 稳定版/1.7.x:

pip install https://github.com/django/django/archive/stable/1.7.x.zip

With BitBucket it's about the same predictable pattern:

使用 BitBucket,它的可预测模式大致相同:

pip install https://bitbucket.org/izi/django-admin-tools/get/default.zip

Here, the master branch is generally named default. This will make your requirements.txt installing much faster.

在这里,master 分支一般被命名为 default。这将使您的 requirements.txt 安装速度更快。

Some other answers mention variations required when placing the package to be installed into your requirements.txt. Note that with this archive syntax, the leading -eand trailing #egg=blah-blahare notrequired, and you can just simply paste the URL, so your requirements.txt looks like:

其他一些答案提到将要安装的包放入requirements.txt. 请注意,这个档案的语法,领先-e和落后#egg=blah-blah不是必需的,你可以只是简单粘贴URL,所以你requirements.txt的样子:

https://github.com/user/repository/archive/branch.zip

回答by Hassek

Just to add an extra, if you want to install it in your pip file it can be added like this:

只是添加一个额外的,如果你想将它安装在你的 pip 文件中,它可以像这样添加:

-e git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6#egg=django-oscar-paypal

It will be saved as an egg though.

不过它会被保存为一个鸡蛋。

回答by Jaakko

Instructions to install from private repo using ssh credentials:

使用ssh 凭据从私有仓库安装的说明:

$ pip install git+ssh://[email protected]/myuser/foo.git@my_version

回答by prosti

You used the egg files install procedure. This procedure supports installing over git, git+http, git+https, git+ssh, git+gitand git+file. Some of these are mentioned.

您使用了egg 文件安装程序。该程序支持安装了gitgit+httpgit+httpsgit+sshgit+gitgit+file。其中一些被提及。

It's good you can use branches, tags, or hashes to install.

您可以使用分支、标签或散列进行安装,这很好。

@Steve_K noted it can be slow to install with "git+" and proposed installing via zip file:

@Steve_K 指出使用“git+”安装可能很慢,建议通过 zip 文件安装:

pip install https://github.com/user/repository/archive/branch.zip

Alternatively, I suggest you may install using the .whlfile if this exists.

或者,我建议您可以使用该.whl文件进行安装(如果存在)。

pip install https://github.com/user/repository/archive/branch.whl

It's pretty new format, newer than egg files. It requires wheel and setuptools>=0.8 packages. You can find more in here.

这是一种非常新的格式,比egg 文件更新。它需要wheel和setuptools>=0.8包。您可以在此处找到更多信息

回答by Deepak Sharma

This worked like charm:

这就像魅力一样:

pip3 install git+https://github.com/deepak1725/fabric8-analytics-worker.git@develop

Where :

在哪里 :

develop: Branch

开发:分支

fabric8-analytics-worker.git : Repo

fabric8-analytics-worker.git :回购

deepak1725: user

deepak1725:用户