Does pip handle extras_requires from setuptools/distribute based sources?
Asked Answered
I

3

48

I have package "A" with a setup.py and an extras_requires line like:

extras_require = {
    'ssh':  ['paramiko'],
},

And a package "B" that depends on util:

install_requires = ['A[ssh]']

If I run python setup.py install on package B, which uses setuptools.command.easy_install under the hood, the extras_requires is correctly resolved, and paramiko is installed.

However, if I run pip /path/to/B or pip hxxp://.../b-version.tar.gz, package A is installed, but paramiko is not.

Because pip "installs from source", I'm not quite sure why this isn't working. It should be invoking the setup.py of B, then resolving & installing dependencies of both B and A.

Is this possible with pip?

Illa answered 25/1, 2011 at 17:41 Comment(1)
Update your pip pip install -U pip and then pip install ".[test]" should install named extra_require sectionSluiter
R
22

This is suppported since pip 1.1, which was released in February 2012 (one year after this question was asked).

Rob answered 26/1, 2011 at 15:38 Comment(2)
That appears to be it. My grep over the pip source tree didn't turn it up, as I was looking for the string "extras_require", not just "extras".Illa
For posterity, use pip install packagename[extra1,extra2]==2.1 as described in example 6 here and in this post.Ternion
N
43

We use setup.py and pip to manage development dependencies for our packages, though you need a newer version of pip (we're using 1.4.1 currently).

#!/usr/bin/env python
from setuptools import setup
from myproject import __version__ 

required = [
    'gevent',
    'flask',
    ...
]

extras = {
    'develop': [
        'Fabric',
        'nose',
    ]
}

setup(
    name="my-project",
    version=__version__,
    description="My awsome project.",
    packages=[
        "my_project"
    ],
    include_package_data=True,
    zip_safe=False,
    scripts=[
        'runmyproject',
    ],
    install_requires=required,
    extras_require=extras,
)

To install the package:

$ pip install -e . # only installs "required"

To develop:

$ pip install -e .[develop] # installs develop dependencies
Nuncupative answered 18/9, 2013 at 18:7 Comment(6)
It appears that pip install .[develop] (without the -e) does not work, and you need to use an editable installation if you want to install extras of ..Divertissement
When using pip install -e .[develop], does pip install gevent and Fabric? And where is this behavior documented?Alephnull
That command will install everything, gevent, flask, Fabric, and nose. Pip internally uses setuptools for their build system pip.pypa.io/en/latest/reference/pip/…. extras_require is an option in setuptools for installing 'extras' pythonhosted.org/setuptools/…Nuncupative
@JeremyBanks Here is the PIP issue. It has already been fixed in the code base, so it should theoretically be fixed in the newest version.Antwanantwerp
Is it possible to install multiple extras_require together? Like combine optional support for 2 different things? .[option1,option2]?Sneeze
is it possible to ONLY install [develop]?Pesticide
R
22

This is suppported since pip 1.1, which was released in February 2012 (one year after this question was asked).

Rob answered 26/1, 2011 at 15:38 Comment(2)
That appears to be it. My grep over the pip source tree didn't turn it up, as I was looking for the string "extras_require", not just "extras".Illa
For posterity, use pip install packagename[extra1,extra2]==2.1 as described in example 6 here and in this post.Ternion
C
22

The answer from @aaronfay is completely correct but it may be nice to point out that if you're using zsh that the install command pip install -e .[dev] needs to be replaced by pip install -e ".[dev]".

Comprehensible answered 8/3, 2019 at 13:5 Comment(1)
I thought I am stupid but now I know: "zsh uses square brackets for globbing / pattern matching."Crudden

© 2022 - 2024 — McMap. All rights reserved.