简体   繁体   English

在python中导入CV2给出未定义的符号错误

[英]Import CV2 in python give undefined symbol error

I have installed opencv 3.4.0 with both python2.7 and python3.5 bindings.我已经安装了带有 python2.7 和 python3.5 绑定的 opencv 3.4.0。 I am able to import and use opencv successfully in python2 but not python3.我可以在 python2 中成功导入和使用 opencv,但不能在 python3 中。 I get the following error:我收到以下错误:

ImportError: /usr/local/lib/libopencv_text.so.3.4: undefined symbol: _ZNK2cv3dnn19experimental_dnn_v33Net14getLayerShapesERKSt6vectorIiSaIiEEiRS3_IS5_SaIS5_EESA导入错误:/usr/local/lib/libopencv_text.so.3.4:未定义符号:_ZNK2cv3dnn19experimental_dnn_v33Net14getLayerShapesERKSt6vectorIiSaIiEEiRS3_IS5_SaIS5_EESA

This worked transiently until I had to upgrade CUDNN for CUDA compatibility purposes.这暂时有效,直到我不得不升级 CUDNN 以实现 CUDA 兼容性。 I have cleaned, uninstalled and reinstalled opencv but this issue is not resolved.我已经清理、卸载并重新安装了 opencv,但是这个问题没有解决。

My additional setup is as follows: Ubuntu 16.04 cuDNN 7.6.1 (I have tried with 7.6.3 as well) CUDA 10.0我的额外设置如下: Ubuntu 16.04 cuDNN 7.6.1(我也尝试过 7.6.3)CUDA 10.0

I am limited to keeping the above versions because of other dependencies.由于其他依赖关系,我仅限于保留上述版本。

Thanks in advance.提前致谢。

A real linux user compile the software by itself :P

Clone opencv and contrib dependencies:克隆 opencv 和 contrib 依赖项:

git clone https://github.com/opencv/opencv.git --depth=1
git clone --depth=1 https://github.com/opencv/opencv_contrib.git

In order to reduce by a huge factor the compilation time (that can be more than 8h in the old environment), you can specify the architecture of the GPU.为了大幅减少编译时间(在旧环境中可能超过 8 小时),您可以指定 GPU 的架构。 (here an example for compile opencv from a source related to the hardware only) (这里是从仅与硬件相关的源编译 opencv 的示例)

NOTE:笔记:
CUDA_GENERATION is related to your GPU ARCH. CUDA_GENERATION 与您的 GPU ARCH 相关。
Change path related to your python libs (replace /opt/XXXXXXXX)更改与您的 python 库相关的路径(替换 /opt/XXXXXXXX)

> export JAVA_HOME=/opt/DEVOPS/SDK/jvm/jdk-11.0.4/ ; cmake3 .. -D \
INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_CUDA=ON \
-D WITH_GTK=ON -D WITH_OPENGL=ON -D ENABLE_CXX11=ON -D BUILD_EXAMPLES=ON \
 -D OPENCV_EXTRA_MODULES_PATH=/opt/SP/packages/opencv_contrib/modules -D \
BUILD_opencv_java=ON -D BUILD_opencv_python2=ON -D BUILD_opencv_python3=ON \ 
-D CUDA_FAST_MATH=ON -D CUDA_GENERATION="Maxwell" -D WITH_OPENMP=ON -D \ 
BUILD_TESTS=OFF -D OPENCV_ENABLE_NONFREE=ON -D BUILD_TIFF=ON -D WITH_OPENCL=ON \ 
-D WITH_IPP=ON -D WITH_TBB=ON -D WITH_EIGEN=ON -D WITH_V4L=ON -D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF -D CMAKE_BUILD_TYPE=RELEASE -D \ 
CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \ 
-D PYTHON3_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 PYTHON3_LIBRARY=/opt/DEVOPS/SDK/anaconda3/lib \ 
-D OPENCV_PYTHON3_INSTALL_PATH=/opt/DEVOPS/SDK/anaconda3/lib/python3.7/site-packages \
 -D PYTHON3_DEFAULT_EXECUTABLE=/opt/DEVOPS/SDK/anaconda3/bin/python \
 -D OPENCV_ENABLE_NONFREE=ON

you should download the ANACONDA python environment, and install opencv through pip using the terminal.您应该下载ANACONDA python环境,并使用终端通过pip安装opencv。

Enter the below command into a python terminal:在 python 终端中输入以下命令:

python -m pip install opencv-python

This should install the latest version of cv2.这应该安装最新版本的 cv2。

Goodluck friend.好运的朋友。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM