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

标签 python python-3.9 nuitka

好吧,我将我的 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/

相关文章:

python - 创建 python 文件可执行文件时出错

python - 用Nuitka编译任何Python程序后,我得到 “is not a valid win32 application”错误

python - 尝试在 mysql 数据库中设置枚举数据类型时出现问题

python - 更高效地实现Textacy/spacy 'subject_verb_object_triples'

python - NumPy linspace 舍入错误

python - PEP8 导入约定

python - Python 中的 __peg_parser__ 是什么?

python - psycopg2 的构建轮失败

python - Nuitka standalone 并不是真正独立的

python - 如何编写迭代器?