python3.x安装cv2失败

发布时间:2019-10-21 09:09:43编辑:auto阅读(4173)

    0

    想给python3装一个opencv的库,结果捣鼓半天,倒给python2.x装上cv2了,而python3里import cv2则一直失败。

    1

    首先想到动态链接库,于是添加/usr/lib/python3.5/site-packagesld.so.conf中。
    失败。

    在网上搜到有答案说要安装python头文件。我查看/usr/include,有python3.5m目录,包含头文件。
    于是想不是这个问题。

    然后想到查看lib中的site-packages目录。于是比较/usr/lib/python3.5/site-packages/usr/lib/python2.7/site-packages目录。发现2.7中有cv2.so,而安装了cv2的python3里只有一个egg-info目录。于是想可能是这个缺.so文件的问题。
    同时在网上看到一答案,指出:对于执行import cv2出现的找不到相关模块的问题其实在OpenCV本身的网站上就有说明:
    “Python 2.6 bindings for OpenCV are included within the package, but not installed. You can copy the subdirectory opencv/Python2.6/Lib/site-packages into the respective directory of the Python installation. This procedure will be automated in the next OpenCV update. ”
    即我们只需要把OpenCV安装目录下的Python2.6/Lib/site-packages中的文件拷贝到Python2.6安装目录下的Lib/site-packages即可。
    把该解决方法套用过来,将OpenCV安装目录下(我的是/usr/local/lib(/python3.5/site-packages))的cv2.cpython-35m-x86_64-linux-gnu.so文件拷贝到python3.5安装目录下的lib/sige-packages目录下(我的是/usr/lib/python3.5/site-packages)即可。
    拷贝过去,测试import cv2,成功,问题解决。

    References

    启发文章

关键字