Specifying OpenCV as Python package prereq

Related: Install OpenCV in Python


An easy way to install OpenCV in Python is simply:

python -m pip install opencv-python

This carries over into your setup.cfg file, simply include:

[options]
setup_requires =
  setuptools >= 38.6
  pip >= 10
  wheel >= 0.31

[options.extras_require]
opencv =
  opencv-python

This allows users to retain their existing OpenCV install, which may be customized / optimized, while giving an easy path for new OpenCV users. You can tell users that if they don’t already have OpenCV, try:

pip install -e .[opencv]

CI

This is also a good technique for continuous integration systems like Travis-CI, in the .travis.yml file include:

install:
- pip install -e .[tests,cov,opencv]

just takes a few seconds.