我试图在使用Ubuntu 14.04的系统上使用Python中的OpenCV。当我尝试导入cv2时,出现以下错误:
me@Bedrock1:~$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libavcodec.so.53: cannot open shared object file: No such file or directory
搜索libavcodec.so.53显示我的系统只有libavcodec.so.54。
搜索互联网后发现,libavcodec.so.53已从14.04存储库(http://www.ubuntuupdates.org/package/core/trusty/universe/base/libavcodec53)中删除。这可能解释了我无法apt-get安装这个库:
me@Bedrock1:~$ sudo apt-get install libavcodec53 libavcodec-extra-53
...
E: Package 'libavcodec53' has no installation candidate
E: Package 'libavcodec-extra-53' has no installation candidate
不幸的是,现在我真的陷入了困境。
有没有办法让cv2模块使用libavcodec.so.54,或者找到&amp;安装libavcodec.so.53?
注意:我刚刚按照https://help.ubuntu.com/community/OpenCV
上的说明尝试重新安装但我仍然得到相同的libavcodec.so.53错误....
答案 0 :(得分:2)
试试这个脚本。 Ubuntu手册页有此脚本的旧版本。这应该有用。
https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/2.4/opencv2_4_9.sh
答案 1 :(得分:1)
检查重新安装opencv是否可以解决问题
sudo apt-get install --reinstall python-opencv
BTW你之前是如何安装它的?
答案 2 :(得分:1)
我在Ubuntu 14.04 64bit上遇到了同样的问题,如下所示: https://bugs.launchpad.net/ubuntu/+source/opencv/+bug/1161485/comments/2 我尝试下载源代码包并重新编译,以便连接正确的库,但没有运气。
最后,我按照以下说明从源代码重新编译: http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html
除了python模块编译外,一切都很顺利,在编译时禁用了(在Opencv模块中列出:不可用:部分)。
我使用cmake-gui配置构建并生成makefile。配置步骤正确设置了PYTHON2_INCLUDE_DIR,PYTHON2_INCLUDE_DIR2和PYTHON2_LIBRARY,但它没有设置PYTHON_INCLUDE_DIR,PYTHON_INCLUDE_DIR2和PYTHON_LIBRARY。
为了实际构建python模块,您应该将这些PYTHON_变量设置为等于其对应的PYTHON2_变量。然后,make步骤也将构建cv2.so。