Last active
August 10, 2021 14:23
-
-
Save tomaszklim/9cf70ada97a3066a6b58c901ea7fcb41 to your computer and use it in GitHub Desktop.
How to build OpenCV 3.x with Python 3.x bindings on Ubuntu 20.04 LTS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download and unpack your chosen OpenCV version., eg. as `/usr/local/src/opencv-3.4.1` | |
# You can use https://github.com/pisecurity/opencv-manager repository as well. | |
# This is important. On Ubuntu 20.04 LTS, it is not enough to install just python-dev. | |
apt-get install python-dev python-numpy python-is-python2 python2.7 python2.7-dev python2.7-minimal | |
# All unrelated build settings were cut off. | |
cd /usr/local/src/opencv-3.4.1/build | |
cmake \ | |
-DENABLE_PRECOMPILED_HEADERS=OFF \ | |
-DBUILD_opencv_python2=ON \ | |
-DBUILD_opencv_python3=ON \ | |
-DCMAKE_INSTALL_PREFIX=/usr/local/opencv-$version \ | |
.. | |
make -k -j2 | |
# Now wait. Everything should build properly, except for `opencv_python3.dir/__/src2/cv2.cpp.o` file. | |
mcedit modules/python3/CMakeFiles/opencv_python3.dir/flags.make | |
# In this file, you should see a veeeery long `CXX_INCLUDES` variable. Near the end, you should see: | |
`-isystem /usr/include/python3.8` | |
# change it to: | |
`-isystem /usr/include/python2.7` | |
# and run "make" again. Now Python 3.x module should be built properly. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment