94

How can one manage to install extras_requires with pip when installing from a git repository ?

I know that you can do pip install project[extra] when the project is on pypi.
And you have to do pip install -e git+https://github.com/user/project.git#egg=project for a git repo but I didn't manage to find how to link these two options together.

PhilipGarnero
  • 1,872
  • 2
  • 17
  • 23

4 Answers4

137

This should work, per example #6

For remote repos:

pip install -e git+https://github.com/user/project.git#egg=project[extra]

And this for local ones (thanks to @Kurt-Bourbaki):

pip install -e .[extra]

As per @Jurt-Bourbaki:

If you are using zsh you need to escape square brackets or use quotes:

pip install -e .\[extra\]
# or
pip install -e ".[extra]"
vinzee
  • 17,022
  • 14
  • 42
  • 60
Alik
  • 22,355
  • 5
  • 46
  • 63
  • Just what I needed! This also works when you define it in requirements.txt or setup.py. – Joren Van Severen May 28 '15 at 10:51
  • 2
    But what if `pip install -e .` is used, and not a URL? – ankostis Dec 02 '16 at 18:57
  • 50
    @ankostis `pip install -e .[extra]` should work. If you're using `zsh` you need to escape square brackets: `pip install -e .\[extra\]`. – Kurt Bourbaki Dec 07 '16 at 18:55
  • Also notice that if requirements from `setup.py` are not being installed by `pip` it may be because [you have an *egg.info folder next to setup.py](https://github.com/pypa/pip/issues/4780) – Michele Piccolini Jun 05 '20 at 12:22
  • Thank you, this is exactly what I needed as well. I am just wondering, what if the git repo contains multiple packages which are not listed in setup.py explicitly, i.e. with 'find_packages' and I want to use `git+https...` to get the same installation as with `pip install -e .[extra]`? This `pip install -e git+https://github.com/user/project.git#egg=.[extra]` does not work. – Paloha Apr 15 '21 at 07:55
  • 3
    On Windows, Powershell will complain about the brackets. Simply put the argument between double quotes, e.g: `pip install -e ".[extra]"` – Epoc Sep 16 '21 at 16:28
  • @ankostis your answer helps if you're using `zsh`, but quotes as suggested by @Epoc also work (probably for any shell/platform). So the answer should be: `pip install -e ".[extra]"` – dyoll Sep 28 '21 at 16:43
36

Important to notice: you should not have whitespaces around or within brackets. I.e. this will work: -e ".[extra1,extra2]" but this won't: -e ". [extra1, extra2]" - and even as a row in requirements.txt file, where it is not so obvious. The worst thing about it is that when you have whitespace, extras are just silently ignored.

paulmelnikow
  • 16,470
  • 7
  • 60
  • 112
MarSoft
  • 3,202
  • 30
  • 37
  • 1
    I haven't seen this documented anywhere for multiple extras but it's a quite important tip! – bastula Apr 03 '18 at 17:50
  • @bastula you're right, it is seemingly undocumented - but at least as of time of writing it was the way it behaved. – MarSoft Apr 04 '18 at 13:39
5

This also works when installing from a whl file so, for example, you can do:

pip install path/to/myapp-0.0.1-py3-none-any.whl[extra1]

This is very far from clear from the docs, and not particularly intuitive.

AntonOfTheWoods
  • 516
  • 8
  • 14
0

Using git + ssh to install packages with extras from private repositories:

pip install -e 'git+ssh://git@github.com/user/project.git#egg=project[extra1,extra2]'
Connor Dibble
  • 438
  • 2
  • 12
  • 1
    There should be no space between the extras. Also, installing packages with git is already covered in the accepted answer, albeit with `https` not `ssh`. I'd say this answer would work best as an edit over the accepted one, striving to cumulate and structure the knowledge – Ciprian Tomoiagă May 31 '21 at 13:42