python3.8版本执行labelme,出现TypeError: ‘type‘ object is not subscriptable解决方式

介绍

这段时间太忙了,一直没有抽出时间写博客,说好一个月一篇的,还是拉下了,争取这个月再写一篇。偶然间看到SAM已经集成进labelme中,想试着用用看,是不是传说中的分割一切。谁知道以前python3.8版本的时候还能用,然后我装了最新版本labelme后直接寄了,淦!!!后来查了下,终于知道原因了

___哈哈哈小小记录下 damn!

具体报错信息

报错如下:

(py38) C:\Users\86182>labelme
Traceback (most recent call last):
  File "D:\miniconda3\envs\py38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\miniconda3\envs\py38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\miniconda3\envs\py38\Scripts\labelme.exe\__main__.py", line 4, in <module>
    from labelme.__main__ import main
  File "D:\miniconda3\envs\py38\lib\site-packages\labelme\__main__.py", line 14, in <module>
    from labelme.app import MainWindow
  File "D:\miniconda3\envs\py38\lib\site-packages\labelme\app.py", line 22, in <module>
    from labelme import ai
  File "D:\miniconda3\envs\py38\lib\site-packages\labelme\ai\__init__.py", line 5, in <module>
    from .text_to_annotation import get_rectangles_from_texts  # NOQA: F401
  File "D:\miniconda3\envs\py38\lib\site-packages\labelme\ai\text_to_annotation.py", line 10, in <module>
    model: str, image: np.ndarray, texts: list[str]
TypeError: 'type' object is not subscriptable


截图如下:
在这里插入图片描述

源码修改和报错原因

直接说原因,不墨迹:Python 3.8 及更早版本中的 list 类型不支持使用 list[str] 这样的下标类型注解,这种语法只有在 Python 3.9 或更高版本中才被支持。所以,list[str] 在 Python 3.8 环境中会引发 TypeError: 'type' object is not subscriptable 错误

下面是我的python版本

在这里插入图片描述

验证:

我们验证是不是这个原因,可以看到跟上面报错一模一样

在这里插入图片描述

我们将它改一下,改成下面这种方式,可以看到代码跑起来了兄弟们!按照这个思路,我们直接改源码

在这里插入图片描述

源码修改

从报错中我们知道报错文件他是在"D:\miniconda3\envs\py38\Lib\site-packages\labelme\ai\text_to_annotation.py"中的,具体文件位置每个人都不同,但一定是text_to_annotation.py文件

在这里插入图片描述

跑起来了!!!!

在这里插入图片描述

完结!!!!(派蒙真可爱!)

在这里插入图片描述

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值