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.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 .[opencv]

CI

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

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

just takes a few seconds.