Ask Your Question

Revision history [back]

Compile Python3 lib of OpenCV3.4.10

I am trying to compile the Python3 and Python 2 module for OpenCV in a Dockerfile on a Jetson Nano. Specifically, I want the cv2 files so I can use a command like import cv2 in a Python 3 script.

Although CMake finds a suitable version of Python 2 and 3:

[Build]   [main] -- Found PythonInterp: /usr/local/bin/python2.7 (found suitable version "2.7.17", minimum required is "2.7")
[Build]   [main] -- Found PythonLibs: /usr/local/lib/libpython2.7.a (found suitable exact version "2.7.17")
[Build]   [main] -- Found PythonInterp: /usr/local/bin/python3 (found suitable version "3.6.9", minimum required is "3.2")
[Build]   [main] -- Found PythonLibs: /usr/local/lib/libpython3.6m.a (found suitable exact version "3.6.9")

It appears to ignore it as far as creating the python install libraries:

[Build]   [main] --   Python 2:
[Build]   [main] --     Interpreter:                 /usr/local/bin/python2.7 (ver 2.7.17)
[Build]   [main] --     Libraries:                   NO
[Build]   [main] --     numpy:                       /usr/local/lib/python2.7/site-packages/numpy/core/include (ver 1.16.6)
[Build]   [main] --     install path:                -
[Build]   [main] --
[Build]   [main] --   Python 3:
[Build]   [main] --     Interpreter:                 /usr/local/bin/python3 (ver 3.6.9)
[Build]   [main] --     Libraries:                   NO
[Build]   [main] --     numpy:                       /usr/local/lib/python3.6/site-packages/numpy/core/include (ver 1.18.3)
[Build]   [main] --     install path:                -
[Build]   [main] --
[Build]   [main] --   Python (for build):            /usr/local/bin/python2.7

I've looked all over the web for days and days to try to solve, and have tried many variations in my cmake. Here is everything I've thrown at it:

/usr/src/app/cmake-3.17.2/build/bin/cmake -D WITH_CUDA=ON \
          -D CUDA_ARCH_BIN="5.3" \
          -D BUILD_LIST=cudev,highgui,videoio,video,cudaimgproc,ximgproc \
          -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.10/modules \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D CMAKE_BUILD_TYPE=Release \
          -D PYTHON3_EXECUTABLE=$(which python3.6) \
          -D PYTHON2_EXECUTABLE=$(which python2.7) \
          -D PYTHON2_INCLUDE_DIR=$(python2.7 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
          -D PYTHON2_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/python2.7 \
          -D PYTHON3_INCLUDE_DIR=$(python3.6 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
          -D PYTHON3_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/python3.6m \
          -D PYTHON2_LIBRARY=/usr/lib/python2.7/config-aarch64-linux-gnu/libpython2.7.so \
          -D PYTHON3_LIBRARY=/usr/lib/python3.6/config-3.6m-aarch64-linux-gnu/libpython3.6.so \
          -D PYTHON2_NUMPY_INCLUDE_DIR=$(python2.7 -c "import numpy; print(numpy.get_include())") \
          -D PYTHON3_NUMPY_INCLUDE_DIR=$(python3 -c "import numpy; print(numpy.get_include())") \
          -D INSTALL_PYTHON_EXAMPLES=ON \
          -D BUILD_opencv_python3=ON \
          -D BUILD_opencv_python2=ON \
          -D HAVE_opencv_python2=ON \
          -D HAVE_opencv_python3=ON \
          -D PYTHON_DEFAULT_EXECUTABLE=$(which python2.7) \
          -D BUILD_NEW_PYTHON_SUPPORT=ON \
          -D BUILD_PYTHON_SUPPORT=ON \
          -D OPENCV_PYTHON3_INSTALL_PATH=/usr/src/app \
          -D BUILD_TESTS=OFF \
          -D BUILD_PERF_TESTS=OFF \
          -D PYTHON3_CVPY_SUFFIX=.cpython-36m-aarch64-linux-gnu.so \
          -D WITH_GSTREAMER=ON \
          -D WITH_GSTREAMER_0_10=OFF \
          -D WITH_CUDA=OFF \
          -D WITH_TBB=ON \
          -D WITH_LIBV4L=ON \
          -D WITH_FFMPEG=ON .. && make -j8 && make install

I've tried many combinations and permutations with no luck. Any suggestions would be appreciated!