Specify extras_require with pip install -e

Question:

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.

Asked By: PhilipGarnero

||

Answers:

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]"
Answered By: Konstantin

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.

Answered By: MarSoft

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.

Answered By: AntonOfTheWoods

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

pip install -e 'git+ssh://[email protected]/user/project.git#egg=project[extra1,extra2]'
Answered By: Connor Dibble

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]"
Answered By: Medhat Gayed

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

Answered By: chicxulub
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.