【问题标题】:pip install from git repo branch从 git repo 分支安装 pip
【发布时间】:2013-12-04 19:02:41
【问题描述】:

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

pip install 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。

如何安装这个分支?

【问题讨论】:

  • 对我来说你的建议工作例如pip install https://github.com/user/repo.git@branchpip install -U git+https://github.com/moskomule/anatome.git@dev 工作。也许删除多余的/

标签: python git pip


【解决方案1】:

在 URL 前加上前缀 git+(参见 VCS Support):

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

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

【讨论】:

  • 是否必须通过@ 指定分支或提交?
  • @eugene, No, @ 和之后的部分是可选的。
  • @SalahAdDin,我不明白您所说的tree 是什么意思。答案中的给定命令工作正常:i.imgur.com/5q9F0CC.png
  • 用于分支,例如:pip install -U git+https://github.com/danreeves/wagtailgmaps@3.0.0
  • 您也可以将类似git+https://github.com/adiralashiva8/robotframework-metrics@v3.1.4 的内容放入您的requirements.txt 中,然后使用pip install -r requirements.txt 进行安装。这将从 master 分支安装 Tag v3.1.4。
【解决方案2】:

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

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

变成了 Django master:

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

对于 Django stable/1.7.x:

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

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

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

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

其他一些答案提到了将要安装的软件包放入您的requirements.txt 时所需的变化。请注意,使用此归档语法,前导 -e 和尾随 #egg=blah-blah不需要的,您只需粘贴 URL,因此您的 requirements.txt 如下所示:

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

【讨论】:

  • 注意: 从 Django 1.9 开始,Django 附带了一个包含 unicode filename 的文件。 pip 扼流圈使用的拉链提取器。一个简单的解决方法是将.zip 替换为.tar.gz,因为焦油提取器可以工作。
  • 我想知道 pip 在克隆时是否可以通过--depth 0 以提高效率(不需要整个 git 历史记录来为 pip 安装快照)。 git-scm.com/docs/git-clone
  • 这也适用于提交哈希! pip install https://github.com/django/django/archive/ebaa08b.zip
  • 感谢您指出速度差异。我没有测试和比较它们,但我相信速度差异确实存在,因为从分支安装仍然会导致下载整个回购历史,而从.zip(或.tar.gz)安装只会导致下载回购的快照。
  • 是否可以使用这种语法安装附加组件?例如,我正在尝试安装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 和安装。
【解决方案3】:

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

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

不过会保存为鸡蛋。

【讨论】:

  • 最好在没有-e 的情况下使用它。见:stackoverflow.com/a/34518202/451710
  • 感谢您的评论,非常有趣。我认为人们倾向于使用-e 标志来避免与已经存在的包发生任何可能的冲突。我猜是选择问题
  • 如果你想要“额外”,请将它们附加到他的片段中,就像这样:-e git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6#egg=django-oscar-paypal[PDF]
  • 请注意,-e 实际上似乎不是必需的。
  • 出于某种原因,没有-e,它对我不起作用
【解决方案4】:

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

$ pip install git+ssh://git@github.com/myuser/foo.git@my_version

https://pip.pypa.io/en/stable/topics/vcs-support/

【讨论】:

  • 我们能得到这个的源代码/文档吗?我喜欢这个解决方案。
  • 我不确定在哪里找到它。
  • @JustinRice official documentation for pip 可能是一个很好的来源。
【解决方案5】:

您使用了 egg 文件安装程序。 此过程支持通过gitgit+httpgit+httpsgit+sshgit+gitgit+file 安装。提到了其中的一些。

你可以使用分支、标签或哈希来安装。

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

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

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

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

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

【讨论】:

  • 问题未指定给github。 archive/branch.zip 的概念仅适用于 github。
【解决方案6】:

这就像魅力:

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

地点:

开发:分支

fabric8-analytics-worker.git:回购

deepak1725:用户

【讨论】:

    【解决方案7】:

    对于 windows 和 pycharm 设置:

    如果你正在使用 pycharm 并且如果你想使用pip3 install git+https://github.com/...

    【解决方案8】:

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

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

    具体翻译为做

    pip install -U git+https://github.com/moskomule/anatome.git@dev
    

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

    (original_anatome_env) brando~/ultimate-anatome ❯ pip install -U git+https://github.com/moskomule/anatome.git@dev
    Collecting git+https://github.com/moskomule/anatome.git@dev
      Cloning https://github.com/moskomule/anatome.git (to revision dev) to /private/var/folders/x4/0xq0brj57xz3dbhbmblypbm00000gr/T/pip-req-build-62d_ghd2
      Running command git clone -q https://github.com/moskomule/anatome.git /private/var/folders/x4/0xq0brj57xz3dbhbmblypbm00000gr/T/pip-req-build-62d_ghd2
      Running command git checkout -b dev --track origin/dev
      Switched to a new branch 'dev'
      Branch 'dev' set up to track remote branch 'dev' from 'origin'.
      Resolved https://github.com/moskomule/anatome.git to commit 4b576e51cb1824a57ea04974e0f92b5a6143294d
    Requirement 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)
    Requirement 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)
    Requirement 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)
    Requirement 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)
    Requirement 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)
    Building wheels for collected packages: anatome
      Building wheel for anatome (setup.py) ... done
      Created wheel for anatome: filename=anatome-0.0.6-py3-none-any.whl size=10167 sha256=63b12a36f33deb8313bfe7756be60bd08915b8ba36711be47e292b590df70f61
      Stored in directory: /private/var/folders/x4/0xq0brj57xz3dbhbmblypbm00000gr/T/pip-ephem-wheel-cache-rde_ngug/wheels/19/e4/be/01479e8cba62ae8cdcd501cd3bf49e199f2bb94732a6a1b006
    Successfully built anatome
    Installing collected packages: anatome
      Attempting uninstall: anatome
        Found existing installation: anatome 0.0.5
        Uninstalling anatome-0.0.5:
          Successfully uninstalled anatome-0.0.5
    Successfully installed anatome-0.0.6
    

    0.6.0 是 dev 分支版本号,0.5.0 是 master,所以成功了!

    【讨论】:

      猜你喜欢
      • 2020-04-25
      • 2023-04-03
      • 2019-08-03
      • 1970-01-01
      • 1970-01-01
      • 2016-09-24
      相关资源
      最近更新 更多