120

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
  • 2,399
  • 4
  • 17
  • 24

7 Answers7

183

This should work, per examples #6 and #7

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 @Kurt-Bourbaki:

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

pip install -e .\[extra\]
# or
pip install -e ".[extra]"

As per @Epoc:

Windows Powershell will also require quoting the brackets.

Kevin Horn
  • 4,167
  • 28
  • 30
Konstantin
  • 24,271
  • 5
  • 48
  • 65
  • 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
  • 55
    @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
  • 4
    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
  • The notation for git seems to be now outdated, see: https://stackoverflow.com/a/75780980 – sinoroc Mar 19 '23 at 10:30
43

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,895
  • 8
  • 63
  • 114
MarSoft
  • 3,555
  • 1
  • 33
  • 38
  • 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
11

It may not be obvious for some users, and wasn't for me, so thought to highlight that extra in the following command

pip install -e ".[extra]"

needs to be replaced by the actual name of the extra requirements.

Example:

You add options.extras_require section to your setup.cfg as follows:

[options.extras_require]
  test =
    pre-commit>=2.10.1,<3.0
    pylint>=2.7.2,<3.0
    pytest>=6.2.2,<7.0
    pytest-pspec>=0.0.4,<1.0

Then you install the test extra as follows

pip install -e ".[test]"
Medhat Gayed
  • 2,585
  • 20
  • 12
  • The options.extras_require section doesn't work for me, resulting in errors. If my pyproject.toml has an options.extras_require, either it is ignored, either it errors out about invalid TOML, and Google search only gives me results about that now incorrect syntax. What do I do then? – Eric Buist Jun 04 '23 at 19:30
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
  • 809
  • 13
  • 17
4

To install project's extra requirements under extra from git, the more modern syntax is

python -m pip install -e "project[extra] @ git+https://github.com/user/project.git"

Source: in the pip documentation Examples, see "Install a package with extras".

Installing via the command in the current accepted answer—

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

—will raise this warning:

DEPRECATION: git+https://github.com/user/project.git#egg=project[extra] contains an egg fragment with a non-PEP 508 name pip 25.0 will enforce this behaviour change. A possible replacement is to use the req @ url syntax, and remove the egg fragment. Discussion can be found at https://github.com/pypa/pip/issues/11617

chicxulub
  • 210
  • 2
  • 5
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
  • 517
  • 3
  • 13
  • 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
0

setup.cfg does not behave the same as requirements.txt, at the end there is an workaround for that

# setup.cfg
...
[options.extras_require]
dev =
    pytest
    pytest-cov
    pylint
    coverage
    mypy
    types-requests
    custolint

ciur =
    # ciur==0.2.0
    ciur # 0.2.0

selenium =
    ada-automation.selenium-bot
...
# setup.py

from setuptools import setup

setup()

To install editable

pip install \
    -e "${BITBUCKET_ORG_REPOS}/ada-automation/scraping_bot/_lib" \
    -e "${BITBUCKET_ORG_REPOS}/python-ciur" \
    -e ".[ciur,selenium,dev]"

Confirm that is editable


> pip list | egrep 'ciur|selenium|pytest'
ada-automation.selenium-bot 0.0.0      /Users/xxx/bitbucket.org/ada-automation/scraping_bot/_lib
ciur                        0.2.0      /Users/xxx/bitbucket.org/python-ciur
pytest                      7.4.0
pytest-cov                  4.1.0
selenium                    4.0.0

Andrei.Danciuc
  • 1,000
  • 10
  • 24