pythonpiprequirements.txt

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


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?


Solution

  • 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).