当前位置:   article > 正文

安装cv2_pip install cv2

pip install cv2

安装pip

查看系统所有的python版本

ls /usr/bin/python*
  • 1

在这里插入图片描述

显示系统默认安装python2.7与python3.8,检查当前使用的版本

python --version
python2.7
  • 1
  • 2

我想使用python3 需要一下命令更改优先级

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
  • 1

检查一下
在这里插入图片描述
安装pip3

sudo apt install python3-pip
  • 1

查看安装的pip版本

pip3 --version
  • 1

在这里插入图片描述
pip一定要更改为国内源
在根目录新建.pip文件夹

mkdir .pip
cd .pip
vim pip.conf
  • 1
  • 2
  • 3

复制以下内容使用国内豆瓣源

[global]
timeout = 60
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
  • 1
  • 2
  • 3
  • 4

:wq 命令保存退出

安装cv2

用pip安cv2主模块和contrib模块

pip install opencv-python-headless
pip install opencv-contrib-python-headless
  • 1
  • 2

很快就安装好了,看开能不能成功import

import cv2
  • 1

没有报错就安装好了

安装支持gstreamer的cv2

添加ppa源,搜索的时候可以在网址最后加上?field.series_filter=focal过滤ubuntu版本

sudo add-apt-repository ppa:trinitronx/focal-backport-buildeps
sudo apt update
  • 1
  • 2

然后安装

sudo apt install python3-opencv
  • 1

查看是否支持gstreamer

import cv2
print(cv2.getBuildInformation())
  • 1
  • 2

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/473316
推荐阅读
相关标签
  

闽ICP备14008679号