gpt4 book ai didi

python - 类型错误 : type 'types.GenericAlias' is not an acceptable base type

转载 作者:行者123 更新时间:2023-12-05 04:51:52 52 4
gpt4 key购买 nike

好吧,我将我的 python 项目编译成一个可执行文件,它在我的电脑上运行,但我将它发送给几个 friend 进行测试,他们都遇到了这个错误。我以前从未见过这样的错误。我使用 Nuitka 来编译代码。

Traceback (most recent call last):   File "C:\Python39\lib\inspect.py", line 35, in <module>
import ast File "C:\Python39\lib\ast.py", line 29, in <module>
from contextlib import contextmanager, nullcontext File "C:\Python39\lib\contextlib.py", line 4, in <module>
import _collections_abc File "C:\Python39\lib_collections_abc.py", line 416, in <module>
class _CallableGenericAlias(GenericAlias): TypeError: type 'types.GenericAlias' is not an acceptable base type`

最佳答案

我知道我做这件事已经很晚了,但它可能会在将来帮助别人,

警告:此解决方案涉及处理源文件,我对此很满意,因为我是在隔离的 conda 环境中使用它的。在实现之前确保您了解自己在做什么,因为显然我不了解。

我应用了指出的解决方案in this post它以某种方式解决了我的问题。

基本上我进入源 _collections_abc.py 源文件并将 _CallableGenericAlias(GenericAlias) 中的变量 GenericAlias 交换为 _CallableGenericAlias(GenericAlias) ,它在开头声明为GenericAlias = type(list[int])_CallableGenericAlias(GenericAlias) 到 _CallableGenericAlias(list[int])

再次提醒,谨慎使用,因为我也不完全明白这是怎么回事。

找到原始帖子 here

关于python - 类型错误 : type 'types.GenericAlias' is not an acceptable base type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66728664/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com