Add cv2 graphics / headless extras to setup.py #2775
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The mmcv library requires the cv2 module, but there are two flavors of the module that different users may want in different circumstances, either
opencv-python
oropencv-python-headless
. These libraries are incompatible with each other, and if you incorrectly install the wrong one it becomes a pain to clean them up and install the right one.This PR introduces a way for the user to specify which one of these they want at install time.
Modification
I've added two new files in
requirements
.cv2-headless.txt
andcv2-graphics.txt
which specify reasonable minimum versions of opencv based on the version of Python the user is on. These are registered as newextras_require
options. So the new usage would be either:This means you no longer have to install cv2 before / after mmcv, and you can be sure you have the right one for your use case based on the install command you use. I've been using this construct in kwimage and other cv repos for a while now with good success.
This also makes a modification to the
parse_requirements
function in setup.py. I was the original author of this construct and I figured I would update it to the lastest version I'm using in my cookiecutter repo while I was here. I don't think it matters to parse the new extra reqs, but it does support more cases that could exist in the future. That could be reverted if needbe.Notes
I think to finialize this PR there will need to be documentation modification and maybe this section:
In the setup.py needs to change? Looking for maintainer feedback about this detail.
Checklist
Before PR:
After PR: