You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python导入Flet包时出现TypeError异常求助

解决导入Flet时出现的TypeError: unhashable type: 'list'问题

问题背景

导入Flet包时触发以下错误,已排查包安装状态、文件名冲突、虚拟环境等问题,仍未解决:

File "p:\blahblah\main.py", line 1, in <module>
    import flet
  File "C:\Python39\lib\site-packages\flet\__init__.py", line 1, in <module>
    from flet import (
  File "C:\Python39\lib\site-packages\flet\audio.py", line 7, in <module>
    from beartype import beartype
  File "C:\Python39\lib\site-packages\beartype\__init__.py", line 57, in <module>
    from beartype._decor.decormain import beartype
  File "C:\Python39\lib\site-packages\beartype\_decor\decormain.py", line 24, in <module> 
    from beartype._data.datatyping import (
  File "C:\Python39\lib\site-packages\beartype\_data\datatyping.py", line 129, in <module>
    BeartypeReturn = Union[BeartypeableT, BeartypeConfedDecorator]
  File "C:\Python39\lib\typing.py", line 243, in inner
    return func(*args, **kwds)
  File "C:\Python39\lib\typing.py", line 316, in __getitem__
    return self._getitem(self, parameters)
  File "C:\Python39\lib\typing.py", line 421, in Union
    parameters = _remove_dups_flatten(parameters)
  File "C:\Python39\lib\typing.py", line 215, in _remove_dups_flatten
    all_params = set(params)
TypeError: unhashable type: 'list'

错误原因

问题根源是beartype最新版本与Python3.9的typing模块不兼容:beartype的类型定义中使用了包含list的Union组合,而Python3.9的Union在去重处理时无法哈希list类型,导致抛出错误。

解决方案

  • 降级beartype到兼容版本:
    执行以下命令安装支持Python3.9的beartype版本:

    pip install beartype==0.14.1
    

    该版本是经过验证可与Python3.9及Flet正常配合的稳定版本。

  • 升级Python版本:
    如果环境允许,将Python升级到3.10或更高版本。新版本的typing模块修复了Union的哈希处理问题,同时beartype的最新版本也完全支持Python3.10+。

  • 验证修复:
    重新运行导入Flet的代码,确认错误不再出现。

内容的提问来源于stack exchange,提问作者Michał Majewski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 01:42:50