pip install from git repo branch
Asked Answered
E

9

1150

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

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

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

How do I install this branch?

Epiphenomenalism answered 20/11, 2013 at 16:46 Comment(1)
to me your suggestion work e.g. pip install https://github.com/user/repo.git@branch doing pip install -U git+https://github.com/moskomule/anatome.git@dev worked. Perhaps remove the extra /?Lebkuchen
I
1529

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

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

And specify the branch name without the leading /.

Innards answered 20/11, 2013 at 16:51 Comment(22)
is it mendatory to specify branch or commit by @ ?Aulos
@eugene, No, @ and parts after that is optional.Innards
@SalahAdDin, I don't understand what you mean by tree. The given command in the answer works fine : i.imgur.com/5q9F0CC.pngInnards
Is for branches, for example: pip install -U git+https://github.com/danreeves/[email protected]Solidus
@SalahAdDin, The command you gave works fine. i.imgur.com/YtzNvMF.png Could you explain more?Innards
I've done this, but there's only 6 text files in the python/lib/site-packages/my_module folder. I'd expect there to be the full source code straight from the github repo.Tilbury
On a related note, how do you switch between branches i.e., dev back to master branch?Aaronaaronic
@Kambiz, issue/34/oscar-0.6 is a branch name as mentioned in the question. Replace that with master / dev as you want. pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@masterInnards
Any idea why I am getting ` Command python setup.py egg_info failed with error code 1 ` ?Inert
Before switching branches, is it recommended to remove the package ... or do anything else before switching?Elnaelnar
@rickhg12hs, pip install ... will remove package before update; I don't do anything. Is there anything in mind?Innards
I want to install the master branch of jupyter console and then switch back to normal pypi jupyter console when it catches up. I am just wondering about gotchas lurking beneath the surface.Elnaelnar
You can also put something like this git+https://github.com/adiralashiva8/[email protected] into your requirements.txt and then install with pip install -r requirements.txt. This will install Tag v3.1.4 from master branch.Artima
After the first time, is there a precise way to tell pip to do a git pull to install the latest version of the branch?Isopropyl
quotes may be required in some cases - in particular if you are installing a certain package from a subdirectory (or adding any additional url params), like : pip install "git+https://github.com/tangentlabs/django-oscar-paypal.git#egg=someName&subdirectory=someSubDirectory"Apply
Is it normal that after doing this type of install, in pip list I am unable to see that a particular package is installed from GiHub, whereas if a package is installed from a local directory, that information is displayed.Imco
@Imco Do you mean pip freeze? imgur.com/PlEF9e3Innards
@Innards I am not interested in pip freeze. I was wondering why pip list indicates which packages were installed from local directories but fails to do so for repository packages.Imco
if i do this with the normal package already installed, how do i import the branch specific version in my python program?Lexical
.git necessary?Clothier
@SmartManoj, .git in URL? It originates from the url shown on github clone button click.Innards
Just copied URL from address bar and it's workedClothier
N
445

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

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

which becomes for Django master:

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

for Django stable/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:

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.

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 -e and trailing #egg=blah-blah are not required, and you can just simply paste the URL, so your requirements.txt looks like:

https://github.com/user/repository/archive/branch.zip
November answered 17/7, 2014 at 19:2 Comment(11)
Note: from Django 1.9 on, Django ships with a file that has a unicode filename. The zip extractor used by pip chokes on that. An easy workaround is to replace .zip with .tar.gz, as the tar extractor works.Scotia
I wonder if pip could pass --depth 0 when cloning to make it more efficient (the entire git history is not needed to install a snapshot for pip). git-scm.com/docs/git-cloneOster
This also works for commit hashes! pip install https://github.com/django/django/archive/ebaa08b.zipCalle
Thanks for pointing out the speed difference. I did not test and compare them, but I believe the speed difference does exist, because installing from a branch would still result in downloading the entire repo history, while installing from a .zip (or .tar.gz) would result in downloading just a snapshot of the repo.Janitajanith
Is it possible to install extras using this syntax? For instance, I'm trying to install github.com/apache/incubator-airflow @ master (the normal PyPI package is apache-airflow) to work with an unreleased version. I'd like to convert the call pip install apache-airflow[crypto, slack] to install these extras with the archive version. I tried pip install https://github.com/apache/incubator-airflow/archive/master.zip[crypto, slack] but this breaks the URL and installation.Unmeant
Okay, so it seems to be possible when running pip install directly and just requires setting the egg name explicitly - pip install https://github.com/apache/incubator-airflow/archive/master.zip#egg=airflow[crypto,slack]. Also the spaces between extras in my previous comment are a mistake. Note that however this syntax with extras does not seem to work in a requirements.txt file.Unmeant
Note that despite pipenv is rather similar to pip, using archives with pipenv will not resolve dependencies.Endblown
FWIW using pip 22 the accepted answer was not any slower than this method, and doesn't appear to clone the entire git history of the repoBushbuck
Found the .zip install to be much faster when using repos that contain multiple levels of submodules. Skipping the recursive submodule downloads offers a speed advantage , but may also break dependencies.Cardie
There are reports that recursive dependency installation doesn't work when you use pipenv for archives, but it works for me. I think it was fixed in 2018-09.Braunstein
See here for adding to requirements.txt.Ensiform
C
185

Instructions to install from private repo using ssh credentials:

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

To install a package from a subdirectory, say stackoverflow

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

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

Commutable answered 10/10, 2017 at 12:15 Comment(3)
Could we get the source/documentation for this? I like this solution.Blaisdell
I'm not actually sure where I found it.Commutable
@JustinRice The official documentation for pip can be a good source.Gamosepalous
C
63

This worked like charm:

pip3 install git+https://github.com/deepak1725/fabric8-analytics-worker.git@develop
Field Value
User deepak1725
Repository fabric8-analytics-worker
Branch develop
Complemental answered 10/3, 2020 at 17:36 Comment(0)
C
59

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

-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.

Catafalque answered 26/2, 2015 at 17:1 Comment(6)
Better to use it without the -e. See: https://mcmap.net/q/21611/-how-to-state-in-requirements-txt-a-direct-github-sourceTweezers
Thanks for the comment, very interesting. I think people tend to use the -e flag to avoid any possible conflict with an already existent package. I guess is a matter of choiceCatafalque
And if you want "extras", append them in he fragment, like that: -e git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6#egg=django-oscar-paypal[PDF]Balthazar
Note that the -e does not actually seem to be required.Unmeant
For some reason, it doesn't work for me without the -eTraitor
@EyalLevin Better to use it WITH the -e. See #16585052Tolkan
C
12

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

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:

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

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

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 the documentation.

Counterchange answered 10/4, 2019 at 17:28 Comment(1)
The question is not specify to github. The notion of an archive/branch.zip is specific to github only.Beautiful
L
11

to me your suggestion from question work e.g.

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

translating concretely to doing

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

worked. Perhaps remove the extra / is redundant. My output:

(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 is the dev branch version number and 0.5.0 is the master, so it worked!

Lebkuchen answered 12/11, 2021 at 16:37 Comment(0)
O
2

If you need to install optional dependencies when using a direct link to a git repository here is the example:

pip install "django[bcrypt] @ git+ssh://[email protected]/django/django.git"
Olli answered 30/12, 2023 at 19:3 Comment(0)
T
-2

For windows & pycharm setup:

If you are using pycharm and If you want to use pip3 install git+https://github.com/...

  • firstly, you should download git from https://git-scm.com/downloads
  • then restart pycharm
  • and you can use pycharm terminal to install what you want

enter image description here

Thrasonical answered 19/12, 2020 at 14:55 Comment(1)

© 2022 - 2024 — McMap. All rights reserved.