【问题标题】:Impossible to install OpenCV Ubuntu (libopencv_core error)无法安装 OpenCV Ubuntu(libopencv_core 错误)
【发布时间】:2016-04-13 10:45:03
【问题描述】:

我正在尝试在 Ubuntu 14.04 上安装 OpenCV 3.0 for Python,但经过多次安装(以及读取 StackOverflow 页面)后,它仍然无法正常工作。

在 Python (Python 2.7) 中导入时输入 import cv2 我收到此错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libopencv_core.so.2.4: cannot open shared object file: No such file or directory

我已经看到这个错误可能是由于文件/etc/ld.so.conf.d/opencv.conf 造成的,因此我在里面写了/usr/local/opencv/ 行,但它没有帮助(实际上我的电脑上没有文件夹opencvin /usr/local/ ...

我按照这个网站上的说明进行安装:http://milq.github.io/install-opencv-ubuntu-debian/

我怀疑在cmake 阶段发生了错误,因为我遇到了像-- Performing Test HAVE_CXX_WMISSING_PROTOTYPES - Failed 这样的故障。我不知道这意味着什么以及它是否对安装很重要......

我还有其他错误,例如

-- checking for module 'gstreamer-base-1.0'

-- package 'gstreamer-base-1.0' not found

make阶段我得到了这个错误

[ 31%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/qrc_window_QT.cpp.o
In file included from /home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:9:0:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp: In function ‘int qInitResources_window_QT()’:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:1749:25: warning: no previous declaration for ‘int qInitResources_window_QT()’ [-Wmissing-declarations]
int QT_MANGLE_NAMESPACE(qInitResources_window_QT)()
^
/usr/include/qt5/QtCore/qglobal.h:100:36: note: in definition of macro ‘QT_MANGLE_NAMESPACE’
# define QT_MANGLE_NAMESPACE(name) name
^
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp: In function ‘int qCleanupResources_window_QT()’:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:1758:25: warning: no previous declaration for ‘int qCleanupResources_window_QT()’ [-Wmissing-declarations]
int QT_MANGLE_NAMESPACE(qCleanupResources_window_QT)()
^
/usr/include/qt5/QtCore/qglobal.h:100:36: note: in definition of macro ‘QT_MANGLE_NAMESPACE’
# define QT_MANGLE_NAMESPACE(name) name
^
[ 31%] Generating opencl_kernels_superres.cpp, opencl_kernels_superres.hpp

你知道哪里错了吗?

【问题讨论】:

  • 您似乎已经安装了与 3.0 冲突的旧 OpenCV 版本(2.4.something)
  • 是的,可能是这样,但我尝试在安装 3.0 版本之前删除 opencv(使用sudo find / -name "*opencv*" -exec rm -i {} \;sudo make unistall)。但也许它没有用。我该怎么办?
  • 不知道 linux ;D。我只是给你一些可能的问题的指示。

标签: python opencv ubuntu


【解决方案1】:

我终于设法解决了我的问题。由于这可能会引起其他人的兴趣,这里我将如何进行。

  1. 我从我的计算机中完全删除了 opencv:

    • sudo make unistall 在我写 sudo make install 的存储库中
    • sudo find / -name "*opencv*" -exec rm -i {} \; 删除所有包含“opencv”的文件
    • sudo find / -name "*cv2.so*" -exec rm -i {} \; 删除所有包含“cv2.so”的文件
    • conda uninstall opencv(如果需要)
  2. 我跟着this link 为 Python2.7 安装了 OpenCV2.4.10:我做了第 5、6、7 和 12 点(其余的对于我想要的没用)。我稍微更改了cmake 命令并输入了

    cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON  -D WITH_OPENGL=ON -D WITH_VTK=ON -D WITH_GTK=ON .. 
    
  3. 现在,如果在 Python 中输入 import cv2 时出现“没有名为 cv2 的模块”之类的错误,请使用以下命令编辑 .bashrc 文件

    export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
    

您必须重新加载 .bashrc 文件 (source .bahsrc) 才能应用更改。

  1. 最后我重新启动了我的电脑。它奏效了!

总而言之,我不知道为什么它以前不起作用,但使用这个版本的 OpenCV 似乎我没有遇到任何问题!

祝你好运!

【讨论】:

  • 我觉得sudo find / -name "$ANYTHING_WITH_WILDCARDS" -exec rm -i {} \; 有点不安。
  • 我在askubuntu.com/questions/564290/… 上发现了这一点。它工作得很好,帮助我解决了我的问题
【解决方案2】:

您没有正确安装它,这就是您无法导入它的原因。这是有关如何安装它的指南(它适用于 .older 版本,但命令相同)。 OpenCV 3.0 Trouble with Installation

【讨论】:

  • 我在 Python 2 上收到错误 ImportError: libopencv_nonfree.so.2.4: cannot open shared object file: No such file or directory,在 Python3 上收到错误 ImportError: libopencv_core.so.3.1: cannot open shared object file: No such file or directory...
  • 您在执行安装指南的第一个命令时是否遇到任何错误?
  • cmake 一个?是的,我遇到了一些错误,就像我在最初的帖子中描述的那样
猜你喜欢
  • 2015-05-11
  • 1970-01-01
  • 2015-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多