Gtk-CRITICAL **: IA__gtk_widget_style_get: assertion ‘GTK_IS_WIDGET (widget)‘ faile

问题
在python3中使用import cv2后使用cv2.imshow() 报错(python3:6706): Gtk-CRITICAL **: IA__gtk_widget_style_get: assertion ‘GTK_IS_WIDGET (widget)’ failed

分析:

1. 通过cv2.__version__打印发现python3中导入的cv2是4.3.0

2. 通过pkg-config --modversion opencv,输出opencv 版本是3.4.8

因此是python3中与本机opencv版本不对问题,通过conda list 查看conda 安装的软件,发现opencv-python是4.3.0版本,所以需要安装与opencv3.4.8相对应的opencv-python.

解决:

1. pkg-config --modversion opencv 查询opencv版本号,例如:‘3.4.8’

2. 在https://pypi.org/project/opencv-python/#history查询对应的版本号并安装,或输入

pip3 install opencv-python==3.4.8
$ pip3 install opencv-python==3.4.8
ERROR: Could not find a version that satisfies the requirement opencv-python==3.4.8 (from versions: 3.4.8.29, 3.4.9.31, 3.4.9.33, 3.4.10.35, 3.4.10.37, 3.4.11.39, 3.4.11.41, 3.4.11.43, 3.4.11.45, 4.1.2.30, 4.2.0.32, 4.2.0.34, 4.3.0.36, 4.3.0.38, 4.4.0.40, 4.4.0.42, 4.4.0.44, 4.4.0.46)
ERROR: No matching distribution found for opencv-python==3.4.8

根据提示安装对应版本号:

pip3 install opencv-python==3.4.8.29

指定源快速安装:

pip3 install --default-timeout=1000 --upgrade opencv-python==3.4.8.29 -i  https://pypi.mirrors.ustc.edu.cn/simple --user
$ pip3 install --default-timeout=1000 --upgrade opencv-python==3.4.8.29 -i  https://pypi.mirrors.ustc.edu.cn/simple --user
Looking in indexes: https://pypi.mirrors.ustc.edu.cn/simple
Collecting opencv-python==3.4.8.29
  Downloading https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/bd/95/f06beabb5e1fa319f02278004efce19e7ebe7a67e69dd7d1820d64b2dab8/opencv_python-3.4.8.29-cp38-cp38-manylinux1_x86_64.whl (28.3 MB)
     |████████████████████████████████| 28.3 MB 469 kB/s 
Requirement already satisfied, skipping upgrade: numpy>=1.17.3 in ./anaconda3/lib/python3.8/site-packages (from opencv-python==3.4.8.29) (1.18.5)
Installing collected packages: opencv-python
Successfully installed opencv-python-3.4.8.29

3. 验证imshow()不再报错。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JoannaJuanCV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值