Python Packaging: OpenCV on Wheels

If you want your open source software project to become popular, the project should be easy to install and distribute. To achieve this, software has to be packaged. With packaging I refer to delivering your software for people around the world so that it can be installed preferably with one command. It's not an easy task: consider the fact that you're probably developing software on certain platform (let's say on Windows) and the software should work on all other possible major operating systems (GNU/Linux, OS X, etc.). Then there's also bitness (32-bit and 64-bit) differences. Because this post is going to be about Python, let's add also different Python versions (2.x and 3.x) to the mix.

Python's packaging system used to be pretty broken and hard to use still a couple of years ago. However, there has been lately a lot of improvements which make life easier for developers and for other Python users. One of these is the pre-built wheel package format for projects which use binary extension modules.

Before wheels existed the package system tried to usually compile the software during install (for example if you did pip install numpy). This of course failed miserably for most of the users because no one excepts that you'll need a complete compiler toolchain to install software. In worst case there was no package out there for your setup and everything had to be done manually. Many of these problematic packages were scientific tools like NumPy, SciPy and OpenCV to mention a few. SciPy is still missing at least Windows wheels due to FORTRAN compilation problems afaik, but that's another story...

Packaging is a very manual process without continuous integration. Free continuous integration systems like Travis, Appveyor and CircleCI have made it possible to use automation for any open source project. In addition to this, advancements in Linux container technology (Docker) have made it even easier to build and test software with different configurations. With these tools anyone can package pretty much anything for almost any language.

I started myself to package OpenCV for Python about 5 months ago because OpenCV maintainers were reluctant to do it themselves. It wasn't suprising that there were also other people interested in this since the installation process for the OpenCV Python extension is rather complicated. Pre-built packages are too missing for many platforms.

After some trial and error the packages are now ready and I hope they bring OpenCV and computer vision closer to users by lowering the installation barrier. The packages are in PyPI (python package index) and can be installed with pip install opencv-python. To import OpenCV, use the default OpenCV way: import cv2. If you're interested how the packages are created, have a look at the package repository. I would like thank c-martinez for the help with Linux and OS X builds. OS X build for Python 3.5 is still missing, but otherwise the builds should cover pretty many Python versions.