python安装opencv


opencv作为一个图像处理工具,在开发过程中经常会用的,记录一下安装方法

  • 1、首先pip安装opencv的python包

    pip install opencv-python
    

    然后在python解释器中导入cv2进行测试,不报错的话就是安装成功了

  • 2、如果报错如下错误,则是缺少必要的环境

    Traceback (most recent call last):
    File "demoall.py", line 6, in <module>
    	import cv2
    File "/usr/local/lib/python3.6/dist-packages/cv2/__init__.py", line 5, in <module>
    	from .cv2 import *
    ImportError: libSM.so.6: cannot open shared object file: No such file or directory
    

    需要执行以下命令,安装依赖库

    apt-get update
    apt-get install apt-file
    apt-file update
    apt-file search libSM.so.6
    apt-get install libsm6
    

    然后再在python解释器中进行导包测试,不报错则opencv可以正常使用,但是一般会出现如下错误

    Traceback (most recent call last):
    File "demoall.py", line 6, in <module>
    import cv2
    File "/usr/local/lib/python3.6/dist-packages/cv2/__init__.py", line 5, in <module>
    from .cv2 import *
    ImportError: libXrender.so.1: cannot open shared object file: No such file or directory
    

    若出现以上错误,执行以下命令安装依赖包

    apt-get install libxrender1
    
  • 3 、安装成功后导入opencv测试
    导入测试
    不报错则安装成功

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐