Platform | Status |
---|---|
Windows | |
Ubuntu |
Work in progress!
The aim of this repository is to provide means to package each new OpenCV release for the most used Python versions and platforms.
At the same time it allows anyone to build a custom version of OpenCV for any Python version: just fork this repo and modify the appveyor.yml
(I'll add Travis later for OS X and GNU/Linux) to fit your needs.
- Installation of OpenCV for Python is pretty hideous:
- Download OpenCV
- Find cv2.pyd from the package
- If it exists, copy it to the root of Python site-packages
- If it does not exist for some reason for your setup, you have to setup the build environment and compile it manually
- Try to import cv2 and hope it works
- Everyone should be able to install OpenCV (or any package for that matter) with pip with a single command without building anything
- Python wheels are nice, we should use them more
The project is structured like a normal Python package with a standard setup.py
file. The build process is as follows (see appveyor.yml
):
- Checkout OpenCV (TO DO: pull only latest tag)
- Find OpenCV version from the sources
- Upgrade pip and install numpy for each Python version
- Build OpenCV
- tests are disabled, otherwise build time increases too much
- build runs twice, once for 32bit and once for 64bit
- both of these builds produce two
.pyd
files, one for py2 and one for py3
- both of these builds produce two
- Copy each
.pyd
file one by one to cv2 folder of this project and generate wheel - Install the generated wheels for each Python version
- Test that the Python versions can import them
- TO DO: upload the wheels to PyPi
Currently the setup.py
file parses OpenCV version information from the OpenCV sources. OpenCV depends on numpy, so setup.py
checks the numpy version also with the help of pip.
As described earlier, the .pyd
file is normally copied to site-packages. I don't want to pollute the root folder, so the __init__.py
file in cv2 folder handles the import logic correctly by importing the actual .pyd
module and replacing the imported cv2 package in sys.modudes
with the .pyd
module.
Linux wheels are built using manylinux
Currently the find_version.py
script searches for the version information from OpenCV sources. The CI build number is then added after the actual OpenCV version to differentiate packages (this repo might have modifications but OpenCV version stays same).
As Python's 2.x releases are slowly approaching legacy state, 2.7.x releases will be the only supported Python 2 versions. On Python 3 side, builds will be run only for the latest release which is at the moment 3.5.1.
There's also a build time limitation (AppVeyor open source builds may take max. 1 hour) which restricts the supported Python versions to two. However, if you wan't to get some other versions, just fork this repo and change the dependencies.