从git repo分支安装pip

goh*_*goh 620 python git pip

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

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

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

我该如何安装这个分支?

fal*_*tru 849

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

pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6
Run Code Online (Sandbox Code Playgroud)

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

  • @eugene,不,`@`和之后的部分是可选的. (8认同)
  • 是否可以通过`@`指定分支或提交? (4认同)
  • 您还可以将类似“git+https://github.com/adiralashiva8/robotframework-metrics@v3.1.4”的内容放入您的requirements.txt中,然后使用“pip install -rrequirements.txt”进行安装。这将从 master 分支安装 Tag v3.1.4。 (4认同)
  • 嘿,现在不必放树了,这会出错。 (3认同)
  • 对于分支,例如:`pip install -U git + https:// github.com/danreeves/wagtailgmaps @ 3.0.0` (3认同)

Ste*_*e K 286

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

pip install https://github.com/user/repository/archive/branch.zip
Run Code Online (Sandbox Code Playgroud)

成为django大师:

pip install https://github.com/django/django/archive/master.zip
Run Code Online (Sandbox Code Playgroud)

对于django stable/1.7.x:

pip install https://github.com/django/django/archive/stable/1.7.x.zip
Run Code Online (Sandbox Code Playgroud)

使用BitBucket,它具有相同的可预测模式:

pip install https://bitbucket.org/izi/django-admin-tools/get/default.zip
Run Code Online (Sandbox Code Playgroud)

这里,主分支通常被命名为default.这将使您的requirements.txt安装更快.

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

https://github.com/user/repository/archive/branch.zip
Run Code Online (Sandbox Code Playgroud)

  • **注意:**来自Django 1.9,Django附带的文件有[unicode filename](https://github.com/django/django/commit/bd059e3f8c6311dcaf8afe5e29ef373f7f84cf26).pip chokes使用的拉链提取器.一个简单的解决方法是将`.zip`替换为`.tar.gz`,因为tar提取器可以工作. (26认同)
  • 这也适用于提交哈希!`pip install https:// github.com/django/django/archive/ebaa08b.zip` (6认同)
  • 我想知道pip是否可以在克隆时传递`--depth 0`以提高效率(不需要为pip安装快照的整个git历史记录).https://www.git-scm.com/docs/git-clone (4认同)
  • 谢谢你指出速度差异.我没有测试和比较它们,但我相信速度差确实存在,因为从分支安装仍然会导致下载整个repo历史,而从`.zip`(或`.tar.gz`)安装会导致只下载回购的快照. (4认同)
  • 好的,所以直接运行 pip install 似乎是可能的,只需要显式设置 Egg 名称 - `pip install https://github.com/apache/incubator-airflow/archive/master.zip#egg=airflow[crypto ,松弛]`。另外,我之前的评论中附加内容之间的空格也是一个错误。但请注意,这种带有 extras 的语法似乎在requirements.txt 文件中不起作用。 (3认同)
  • 是否可以使用此语法安装附加功能?例如,我正在尝试安装 https://github.com/apache/incubator-airflow @ master (普通的 PyPI 包是 apache-airflow)以使用未发布的版本。我想转换调用 `pip install apache-airflow[crypto, slack]` 以使用存档版本安装这些附加功能。我尝试了“pip install https://github.com/apache/incubator-airflow/archive/master.zip[crypto, slack]”,但这破坏了 URL 和安装。 (2认同)
  • 请注意,尽管“pipenv”与“pip”非常相似,但将存档与“pipenv”一起使用将无法解决依赖关系。 (2认同)

Jaa*_*kko 55

使用ssh凭据从私有存储库安装的说明.

用法:

$ pip install git+ssh://git@github.com/myuser/foo.git@my_version
Run Code Online (Sandbox Code Playgroud)

用于开发:

$ git clone git@github.com/myuser/foo.git@my_version
$ pip install --editable ./
Run Code Online (Sandbox Code Playgroud)

  • 我们可以获得这方面的来源/文档吗?我喜欢这个解决方案。 (2认同)

Has*_*sek 48

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

-e git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6#egg=django-oscar-paypal
Run Code Online (Sandbox Code Playgroud)

它虽然会被保存为鸡蛋.

  • 最好在没有`-e`的情况下使用它.请参阅:http://stackoverflow.com/a/34518202/451710 (5认同)
  • 感谢您的评论,非常有趣.我认为人们倾向于使用`-e`标志来避免与已存在的包存在任何可能的冲突.我想这是一个选择问题 (4认同)
  • 如果你想要"额外",将它们添加到片段中,就像那样:``-e git + https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6#egg = Django的奥斯卡贝宝[PDF]`` (4认同)

Dee*_*rma 14

这就像魅力一样:

pip3 install git+https://github.com/deepak1725/fabric8-analytics-worker.git@develop
Run Code Online (Sandbox Code Playgroud)

在哪里 :

开发:分支

fabric8-analytics-worker.git :回购

deepak1725:用户


Cha*_*ker 11

给我你对问题工作的建议,例如

\n
pip install https://github.com/user/repo.git@branch\n
Run Code Online (Sandbox Code Playgroud)\n

具体转化为做

\n
pip install -U git+https://github.com/moskomule/anatome.git@dev\n
Run Code Online (Sandbox Code Playgroud)\n

工作了。也许删除多余的部分/是多余的。我的输出:

\n
(original_anatome_env) brando~/ultimate-anatome \xe2\x9d\xaf pip install -U git+https://github.com/moskomule/anatome.git@dev\nCollecting git+https://github.com/moskomule/anatome.git@dev\n  Cloning https://github.com/moskomule/anatome.git (to revision dev) to /private/var/folders/x4/0xq0brj57xz3dbhbmblypbm00000gr/T/pip-req-build-62d_ghd2\n  Running command git clone -q https://github.com/moskomule/anatome.git /private/var/folders/x4/0xq0brj57xz3dbhbmblypbm00000gr/T/pip-req-build-62d_ghd2\n  Running command git checkout -b dev --track origin/dev\n  Switched to a new branch 'dev'\n  Branch 'dev' set up to track remote branch 'dev' from 'origin'.\n  Resolved https://github.com/moskomule/anatome.git to commit 4b576e51cb1824a57ea04974e0f92b5a6143294d\nRequirement already satisfied: torch>=1.10.0 in /Users/brando/anaconda3/envs/metalearning/envs/original_anatome_env/lib/python3.9/site-packages (from anatome==0.0.6) (1.10.0)\nRequirement already satisfied: torchvision>=0.11.1 in /Users/brando/anaconda3/envs/metalearning/envs/original_anatome_env/lib/python3.9/site-packages (from anatome==0.0.6) (0.11.1)\nRequirement already satisfied: typing-extensions in /Users/brando/anaconda3/envs/metalearning/envs/original_anatome_env/lib/python3.9/site-packages (from torch>=1.10.0->anatome==0.0.6) (3.10.0.2)\nRequirement already satisfied: pillow!=8.3.0,>=5.3.0 in /Users/brando/anaconda3/envs/metalearning/envs/original_anatome_env/lib/python3.9/site-packages (from torchvision>=0.11.1->anatome==0.0.6) (8.4.0)\nRequirement already satisfied: numpy in /Users/brando/anaconda3/envs/metalearning/envs/original_anatome_env/lib/python3.9/site-packages (from torchvision>=0.11.1->anatome==0.0.6) (1.21.4)\nBuilding wheels for collected packages: anatome\n  Building wheel for anatome (setup.py) ... done\n  Created wheel for anatome: filename=anatome-0.0.6-py3-none-any.whl size=10167 sha256=63b12a36f33deb8313bfe7756be60bd08915b8ba36711be47e292b590df70f61\n  Stored in directory: /private/var/folders/x4/0xq0brj57xz3dbhbmblypbm00000gr/T/pip-ephem-wheel-cache-rde_ngug/wheels/19/e4/be/01479e8cba62ae8cdcd501cd3bf49e199f2bb94732a6a1b006\nSuccessfully built anatome\nInstalling collected packages: anatome\n  Attempting uninstall: anatome\n    Found existing installation: anatome 0.0.5\n    Uninstalling anatome-0.0.5:\n      Successfully uninstalled anatome-0.0.5\nSuccessfully installed anatome-0.0.6\n
Run Code Online (Sandbox Code Playgroud)\n

0.6.0 是 dev 分支版本号,0.5.0 是 master 分支,所以它有效!

\n


pro*_*sti 6

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

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

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

pip install https://github.com/user/repository/archive/branch.zip
Run Code Online (Sandbox Code Playgroud)

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

pip install https://github.com/user/repository/archive/branch.whl
Run Code Online (Sandbox Code Playgroud)

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

  • 问题不是指定给github。archive/branch.zip 的概念仅适用于 github。 (2认同)