How to install python module extras with pip requirements.txt file

19,365

The correct syntax would be:

requests[security] == 2.9.1 

The linked docs seems to be for pip v1.1, while the latest stable version is v8.1. The latest docs for pip are here, but you have to click a few more links to get to the formatting specs for requirements (PEP 0508).

Share:
19,365

Related videos on Youtube

Michael Lang
Author by

Michael Lang

I'm a .NET developer! Wheeeeeee! And now I nodeJS too! Woooohoooo!

Updated on September 15, 2022

Comments

  • Michael Lang
    Michael Lang over 1 year

    The pip requirements.txt documentation says that extras may be installed using a line like

    MyPackage==3.0 [PDF]
    

    So in my requirements.txt file I have a line that reads:

    requests==2.9.1 [security]
    

    but instead of installing the security extras for the requests module when I run the command:

    pip install -r requirements.txt
    

    I get an error message suggesting that the format of my file is incorrect:

    Invalid requirement: 'requests==2.9.1 [security]'
    Traceback (most recent call last):
      File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 77, in __init__
        req = pkg_resources.Requirement.parse(req)
      File "/Library/Python/2.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3036, in parse
        req, = parse_requirements(s)
      File "/Library/Python/2.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2980, in parse_requirements
        "version spec")
      File "/Library/Python/2.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2956, in scan_list
        raise RequirementParseError(msg, line, "at", line[p:])
    RequirementParseError: Expected ',' or end-of-list in requests==2.9.1 [security] at  [security]
    

    Does anyone have any idea what I might be doing wrong?

    • Aquiles
      Aquiles about 8 years
      remove the [security] I don't think it's supposed to be there... also your requirement.txt packages should not be done manually rather by running pip freeze > requirements.txt
    • Admin
      Admin about 8 years
      Show the full requirements.txt file; there's possible an error elsewhere.
    • Admin
      Admin about 8 years
      And show your setup.py file. Following the links through suggest you need to have your extras defined in your setup as well.
    • mcepl
      mcepl over 5 years
  • endolith
    endolith over 3 years
    When I try this I just get a lot of errors like Collecting pytest-cov[tests] ... WARNING: pytest-cov 2.10.0 does not provide the extra 'tests' , Collecting numba[fast]<0.47 ... WARNING: numba 0.46.0 does not provide the extra 'fast'"
  • Masklinn
    Masklinn over 2 years
    @endolith requirements files don't support filtering dependencies by extra features of the parent package (there's an extra environment marker but I'm not sure it's used). The syntax here is for depending on a package including the specified extra feature(s). So numba[fast] would be "I depend on numba with "fast" enabled" not "I depend on numba if fast is enabled".