PhilipGarnero
PhilipGarnero

Reputation: 2729

Specify extras_require with pip install -e

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.

Upvotes: 132

Views: 60917

Answers (7)

chicxulub
chicxulub

Reputation: 444

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

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

(Note: Gary's comment below correctly points out that this command doesn't work with the -e editable install flag.)

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

Upvotes: 6

Andrei.Danciuc
Andrei.Danciuc

Reputation: 1137

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

Upvotes: 0

Konstantin
Konstantin

Reputation: 25339

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.

Upvotes: 211

Medhat Gayed
Medhat Gayed

Reputation: 2813

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]"

Upvotes: 19

MarSoft
MarSoft

Reputation: 3913

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.

Upvotes: 45

Connor Dibble
Connor Dibble

Reputation: 595

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]'

Upvotes: 0

AntonOfTheWoods
AntonOfTheWoods

Reputation: 953

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.

Upvotes: 5

Related Questions