从 git repo 分支安装 pip
- 2024-12-03 08:44:00
- admin 原创
- 163
问题描述:
尝试pip
安装 repo 的特定分支。Google 告诉我
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。
我该如何安装这个分支?
解决方案 1:
添加 url 前缀git+
(参见VCS 支持):
pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6
并指定不带前导 的分支名称/
。
解决方案 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 稳定版/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
和尾随,您只需粘贴 URL 即可,因此您的 requirements.txt 如下所示:#egg=blah-blah
https://github.com/user/repository/archive/branch.zip
解决方案 3:
使用ssh 凭证从私有 repo 安装的说明:
$ pip install git+ssh://git@github.com/myuser/foo.git@my_version
要从子目录安装包,例如stackoverflow
$ pip install git+ssh://git@github.com/myuser/foo.git@my_version#subdirectory=stackoverflow
https://pip.pypa.io/en/stable/topics/vcs-support/
解决方案 4:
这很有效果:
pip3 install git+https://github.com/user/repo.git@develop
场地 | 价值 |
---|---|
协议 | https |
用户 | user |
存储库 | repo |
分支 | develop |
这是一个具体的例子:pip3 install git+https://github.com/deepak1725/fabric8-analytics-worker.git@develop
解决方案 5:
只需添加一个额外内容,如果您想将其安装在您的 pip 文件中,可以像这样添加:
-e git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6#egg=django-oscar-paypal
但它将被保存为一个鸡蛋。
解决方案 6:
您使用了 egg 文件安装程序。此过程支持git
在 、git+http
、git+https
、和上进行安装。其中一些在其他答案中提到过git+ssh
。git+git
`git+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
包。您可以在文档中找到更多信息。
解决方案 7:
对我来说你的建议来自问题工作例如
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 是开发分支版本号,0.5.0 是主版本,因此它成功了!
解决方案 8:
如果您需要在使用直接链接到 git 存储库时安装可选依赖项,请参考以下示例:
pip install "django[bcrypt] @ git+ssh://git@github.com/django/django.git"
解决方案 9:
对于 Windows 和 Pycharm 设置:
如果你正在使用pycharm并且想要使用pip3 install git+https://github.com/...
首先,你应该从https://git-scm.com/downloads下载 git
然后重启 pycharm
你可以使用 pycharm 终端安装你想要的东西