TypeError: type 'types.GenericAlias' is not an acceptable base type

Viewed 1926

Okay so I compiled my python project into an executable and it worked on my computer but I sent it to a couple of friends to test and they all got this error. I have never seen an error like this before. I used Nuitka to compile the code.

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`
1 Answers

I know I'm very late for this but it might help someone in the future,

Caution: This solution involves messing around with source files and I was comfortable with that because I was using it in an isolated conda environment. Make sure you understand what you're doing before implementing it because clearly I DON'T.

I applied the solution pointed out in this post and it somehow solved the issue for me.

Basically I went into the source _collections_abc.py source file and swapped the variable GenericAlias in _CallableGenericAlias(GenericAlias) to _CallableGenericAlias(GenericAlias) which was declared at the beginning as GenericAlias = type(list[int]) to _CallableGenericAlias(GenericAlias) to _CallableGenericAlias(list[int])

Again, use with caution, because I also don't fully understand what's going on.

Original post found here

Related