Build Python bindings separately
Hi,
Is it possible to build the Python bindings for OpenCV separately to the main build - something like a standard distutils setup.py?
On our supercomputer cluster we maintain quite a few versions of Python. As with all packages, each new version gets built and installed into it's own directory. Each of these versions needs their own Python bindings, linked against that particular version of Python, so what we usually do is install the main C/C++ libraries as usual and then build Python packages for each version as needed, linking against the already-installed C/C++ libraries. However, I can't work out how to separate the Python binding build for OpenCV from the main C/C++ build.
Our base application tree looks like this at the moment:
/apps/opencv/x.x.x
(OpenCV x.x.x. installation - already have)/apps/python/y.y.y
(Python y.y.y installation - already have)
and we want to build and install the bindings at
/apps/opencv-python/x.x.x-y.y.y
The we can easily allow users to mix and match Python and OpenCV versions using the standard environment modules (e.g. doing module load opencv/1.2.3
, module load python/4.5.6
, module load opencv-python
would add /apps/opencv-python/x.x.x-y.y.y
to PYTHONPATH
.
Could you let me know how we can do this?
Thanks, Ben
1st thing to check: are you building with BUILD_SHARED_LIBS=OFF ?
(so your cv2.so no more depends on further opencv so's at runtime)
then, imho, you should be able to move around your cv2.so as you whish.
That would still involve rebuilding OpenCV for each version of Python, yes? I wanted to just build the Python bindings (i.e.
cv2.so
) and link them against the.so
files in the main OpenCV install. E.g. for standalone packages I'd just make sure the OpenCV libraries are on-path and add-lopencv
or similar to the link line." I wanted to just build the Python bindings (i.e. cv2.so) and link them against the .so files in the main OpenCV install." -- i do not think, this is possible. (i.e. building the python wrappers involves re-building some dependant modules like core, imgproc, etc.)
Hmm, okay - so some of the OpenCV modules depend on libpython.so? That seems unfortunate.
hmm, more like: cv2.so depends on libpython.a (other opencv modules don't)
But do some of the bits of the Python bindings live in the main OpenCV libraries, not just cv2? Otherwise, why does building the Python bindings need to re-build OpenCV modules?
let me put it another way:
the python/java wrappers are script-generated from opencv's src code. then, the resulting stub code has to get linked against 1. python, 2. opencv libs (either static or dynamic)
Ahh, okay. That makes sense, thanks for the link.
I don't know if this helps, but I published recently Python wheels for opencv-python 3.1.0 to PyPI (https://pypi.python.org/pypi/opencv-p...). For example with virtualenvs they can be used to run OpenCV with multiple different Python versions.