32

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?

Michael Lang
  • 2,157
  • 3
  • 22
  • 29
  • 2
    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 – Aquiles Apr 08 '16 at 03:26
  • Show the full requirements.txt file; there's possible an error elsewhere. –  Apr 08 '16 at 03:27
  • And show your `setup.py` file. Following the links through suggest you need to have your extras defined in your setup as well. –  Apr 08 '16 at 03:29
  • 1
    @Aquiles https://medium.com/@tomagee/pip-freeze-requirements-txt-considered-harmful-f0bce66cf895 – mcepl Sep 23 '18 at 15:29

1 Answers1

61

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

Marc J
  • 1,303
  • 11
  • 11
  • 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'"` – endolith Aug 10 '20 at 04:19
  • 1
    @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". – Masklinn Nov 26 '21 at 10:07