我正在尝试从Nvidia-Jetson TX2,Ubuntu 16.04上的源代码构建适用于Python3.5的OpenCV-3.4.4。
现在整个cmake
,make
和make install
进程都运行良好,但是在Python3中,当import cv2
时它仍然失败。
我需要在哪里修复?
在opencv-3.4.4
,mkdir build & cd build
和
cmake \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D PYTHON_EXECUTABLE=$(which python3) \
-D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D BUILD_PNG=OFF -DBUILD_TIFF=OFF -DBUILD_TBB=OFF -DBUILD_JPEG=OFF \
-D BUILD_JASPER=OFF \
-D BUILD_ZLIB=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_opencv_java=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D WITH_OPENCL=OFF \
-D WITH_OPENMP=OFF \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=OFF \
-D WITH_GSTREAMER_0_10=OFF
-D WITH_CUDA=ON -DWITH_GTK=ON \
-D WITH_VTK=OFF \
-D WITH_TBB=ON \
-D WITH_1394=OFF \
-D WITH_OPENEXR=OFF \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-9.0 \
-D CUDA_ARCH_BIN=6.2 \
-D CUDA_ARCH_PTX="" \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_TESTS=OFF \
-D OPENCV_TEST_DATA_PATH="" \
..
它编译成功,构建目标如
...
[ 99%] Built target opencv_test_superres
[100%] Built target opencv_videostab
[100%] Built target opencv_test_videostab
[100%] Built target opencv_python3
然后make -j$(nproc --all)
和sudo make install
仍未发生错误,目标如下,
...
[ 99%] Built target gen_opencv_python_source
[ 99%] Built target opencv_python3
[100%] Built target opencv_traincascade
[100%] Built target opencv_createsamples
[100%] Built target opencv_annotation
[100%] Built target opencv_visualisation
[100%] Built target opencv_interactive-calibration
[100%] Built target opencv_version
Install the project...
opencv_python3
确实在构建目标列表中,但是在python3
中,import cv2
失败,说ImportError: No module named 'cv2'
。
我已经检查了导入库/usr/lib/python3/dist-packages
,没有cv2.so
。
问题出在哪里?我错过了一些cmake选项吗?
谢谢