How can I specify optional dependencies in a pip requirements file? According to the pip documentation this is possible, but the documentation doesn't explain how to do it and I can't find any examples on the web.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Instead of specifying optional dependencies in the same file as the hard requirements, you can create a
optional-requirements.txt
and arequirements.txt
.To export your current environment's packages into a text file, you can do this:
If necessary, modify the contents of the requirements.txt to accurately represent your project's dependencies. Then, to install all the packages in this file, run:
-U
tellspip
to upgrade packages to the latest version, and-r
tells it to install all packages in requirements.txt.In 2015 PEP-0508 defined a way to specify optional dependencies in
requirements.txt
:That means that
yourpackage
needsrequests
for its security option. You can install it as:You are misunderstanding the docs; they are not as clear as they could be. The point in the docs is that with a requirements file you can feel free to specify your full recommended working set of packages, including both necessary dependencies and optional ones. You can add comments (lines beginning with #) to distinguish the two to humans, but pip makes no distinction. You can also have two requirements files, as Daniel suggests.