795

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

pip install git+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?

desertnaut
  • 46,107
  • 19
  • 109
  • 140
goh
  • 22,093
  • 28
  • 79
  • 146

7 Answers7

1076

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

falsetru
  • 314,667
  • 49
  • 610
  • 551
  • 8
    is it mendatory to specify branch or commit by `@` ? – eugene Jan 19 '16 at 09:07
  • 13
    @eugene, No, `@` and parts after that is optional. – falsetru Jan 19 '16 at 09:20
  • @SalahAdDin, I don't understand what you mean by `tree`. The given command in the answer works fine : http://i.imgur.com/5q9F0CC.png – falsetru Mar 10 '17 at 13:33
  • 9
    Is for branches, for example: `pip install -U git+https://github.com/danreeves/wagtailgmaps@3.0.0` – SalahAdDin Mar 10 '17 at 13:34
  • @SalahAdDin, The command you gave works fine. http://i.imgur.com/YtzNvMF.png Could you explain more? – falsetru Mar 10 '17 at 13:42
  • 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. – James T. Dec 19 '17 at 22:10
  • On a related note, how do you switch between branches i.e., dev back to master branch? – Kambiz Apr 20 '18 at 18:45
  • @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@master` – falsetru Apr 20 '18 at 22:34
  • Any idea why I am getting ` Command python setup.py egg_info failed with error code 1 ` ? – qwerty Jun 25 '18 at 19:01
  • Before switching branches, is it recommended to remove the package ... or do anything else before switching? – rickhg12hs Oct 01 '18 at 13:48
  • @rickhg12hs, `pip install ...` will remove package before update; I don't do anything. Is there anything in mind? – falsetru Oct 01 '18 at 15:06
  • I want to install the master branch of [jupyter console](https://github.com/jupyter/jupyter_console) and then switch back to normal [pypi jupyter console](https://pypi.org/project/jupyter_console/) when it catches up. I am just wondering about gotchas lurking beneath the surface. – rickhg12hs Oct 01 '18 at 15:26
  • 4
    You can also put something like this `git+https://github.com/adiralashiva8/robotframework-metrics@v3.1.4` into your requirements.txt and then install with `pip install -r requirements.txt`. This will install Tag v3.1.4 from master branch. – Wlad Aug 07 '19 at 14:21
  • 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? – CivFan Nov 02 '20 at 23:23
  • 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"` – rocksteady Mar 12 '21 at 21:24
  • 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. – MadPhysicist May 20 '21 at 08:56
  • @MadPhysicist Do you mean `pip freeze`? https://imgur.com/PlEF9e3 – falsetru May 20 '21 at 10:42
  • @falsetru 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. – MadPhysicist May 20 '21 at 12:14
356

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
Teymour Aldridge
  • 1,271
  • 9
  • 23
Steve K
  • 9,731
  • 4
  • 36
  • 38
  • 30
    **Note:** from Django 1.9 on, Django ships with a file that has a [unicode filename](https://github.com/django/django/commit/bd059e3f8c6311dcaf8afe5e29ef373f7f84cf26). The zip extractor used by pip chokes on that. An easy workaround is to replace `.zip` with `.tar.gz`, as the tar extractor works. – spectras Jul 03 '16 at 11:56
  • 5
    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). https://www.git-scm.com/docs/git-clone – cs01 Mar 31 '17 at 18:15
  • 7
    This also works for commit hashes! `pip install https://github.com/django/django/archive/ebaa08b.zip` – Fush Apr 12 '17 at 03:31
  • 5
    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. – RayLuo Jun 02 '17 at 20:52
  • Is it possible to install extras using this syntax? For instance, I'm trying to install https://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. – Taylor Edmiston Aug 08 '17 at 01:21
  • 1
    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. – Taylor Edmiston Aug 08 '17 at 01:46
  • Note that despite `pipenv` is rather similar to `pip`, using archives with `pipenv` will not resolve dependencies. – Eugene Pakhomov Jan 02 '18 at 09:11
96

Instructions to install from private repo using ssh credentials:

$ pip install git+ssh://git@github.com/myuser/foo.git@my_version
Jaakko
  • 3,154
  • 20
  • 17
54

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.

Reblochon Masque
  • 30,767
  • 8
  • 43
  • 68
Hassek
  • 8,044
  • 6
  • 40
  • 54
  • 6
    Better to use it without the `-e`. See: http://stackoverflow.com/a/34518202/451710 – Eyal Levin Jan 01 '16 at 19:23
  • 4
    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 choice – Hassek Jan 04 '16 at 17:27
  • 4
    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]`` – ankostis Jan 20 '17 at 18:29
  • Note that the `-e` does not actually seem to be required. – Taylor Edmiston Aug 08 '17 at 01:54
  • For some reason, it doesn't work for me without the `-e` – Kurt Bourbaki Jan 12 '18 at 11:00
12

This worked like charm:

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

Where :

develop: Branch

fabric8-analytics-worker.git : Repo

deepak1725: user

Deepak Sharma
  • 860
  • 11
  • 18
6

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.

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

prosti
  • 27,149
  • 7
  • 127
  • 118
0

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

Ekremus
  • 21
  • 2