Ask Your Question

Compile from source without Python 2 / Java support

asked 2018-04-11 06:15:14 -0500

daniel451 gravatar image

I regularly compile the most recent version of OpenCV 3.X (with GPU-support and stuff) myself and set Python 3 bindings to a user virtual environment via -D PYTHON3_EXECUTABLE=... and so on.

I do not need Python 2 or Java support, but OpenCV always compiles for the system Python 2 / Java in addition to my local C++/Python3 environment, thus I'd like to turn it off completely since Java recently broke the compilation (some ant error).

I already tried -D WITH_PYTHON=OFF and -D WITH_JAVA=OFF, but OpenCV still found Python 2 / Java on the system and compiled with support for them.

How could I disable Python 2 / Java for OpenCV compilation? What would some clean compilation flags for this purpose look like?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-04-11 06:49:49 -0500

berak gravatar image

the resp. cmake options are:

-D BUILD_opencv_java=OFF
-D BUILD_opencv_python=OFF
edit flag offensive delete link more


Thanks! Since this worked for me I guess -D BUILD_opencv_python=OFF is only disabling Python 2?

daniel451 gravatar imagedaniel451 ( 2018-04-12 10:11:51 -0500 )edit

no, this should disable both python 2 and 3

(as well, as it will try to build both, if it's enabled)

berak gravatar imageberak ( 2018-04-12 10:18:54 -0500 )edit

This is strange then...I just tested your proposed solution on my laptop and indeed Java and Python 2 was all set to no in the config. However, I also pass PYTHON3_... config options to specify the Python 3 path, library directory and so on and OpenCV definitely built for my Python 3 virtual environment. import cv2 worked afterwards and also the version was showing 3.4.1 (was 3.3 before).

daniel451 gravatar imagedaniel451 ( 2018-04-12 10:35:30 -0500 )edit

I know this is an old thread, but I came to this same problem today and after delving into the CMakeLists.txt file I realised that there are separate options for BUILD_opencv_python2 and BUILD_opencv_python3. I had to set both of them to OFF before I could get openCV to build in debug mode. If I didn't, then my release-mode build would work just fine, but my debug-mode build would fail because of the absence of python3_d.lib.

Eos Pengwern gravatar imageEos Pengwern ( 2019-01-02 10:46:17 -0500 )edit

Question Tools

1 follower


Asked: 2018-04-11 06:15:14 -0500

Seen: 4,914 times

Last updated: Apr 11 '18