alexdelorenzo / cast_control

📺 Control Chromecasts from Linux and D-Bus

Home Page:https://alexdelorenzo.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot import name 'TypeAlias' from 'typing' Python3.8 fresh install

tomcss opened this issue · comments

When I try running cast_control, I get the error below. I tried installing through pip (0.11.8
.post0) and from github (0.11.9), but both times I get the same error.

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/mpris_server/types.py", line 5, in <module>
    from typing import \
ImportError: cannot import name 'TypeAlias' from 'typing' (/usr/lib/python3.8/typing.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/castctl", line 11, in <module>
    load_entry_point('cast-control==0.11.9', 'console_scripts', 'castctl')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 490, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2854, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2445, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2451, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "<frozen zipimport>", line 259, in load_module
  File "/usr/local/lib/python3.8/dist-packages/cast_control-0.11.9-py3.8.egg/cast_control/app/cli.py", line 11, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/usr/local/lib/python3.8/dist-packages/cast_control-0.11.9-py3.8.egg/cast_control/base.py", line 11, in <module>
  File "/usr/local/lib/python3.8/dist-packages/mpris_server/__init__.py", line 1, in <module>
    from . import adapters, base, types, server, mpris, interfaces
  File "/usr/local/lib/python3.8/dist-packages/mpris_server/adapters.py", line 5, in <module>
    from .base import URI, MIME_TYPES, PlayState, DEFAULT_RATE, Microseconds, \
  File "/usr/local/lib/python3.8/dist-packages/mpris_server/base.py", line 10, in <module>
    from .types import TypedDict, TypeAlias, \
  File "/usr/local/lib/python3.8/dist-packages/mpris_server/types.py", line 11, in <module>
    from typing_extensions import \
ImportError: cannot import name '_GenericAlias' from 'typing_extensions' (/usr/local/lib/python3.8/dist-packages/typing_extensions.py)

cast-control-0.11.8.post0
Python 3.8.10

In my case, the typing package lacks of TypeAlias and GenericAlias, and the typing-extensions package lacks of _GenericAlias.

I tried to use the _GenericAlias from the typing package, but it threw TypeError: 'type' object is not subscriptable from the mpris_server/base.py, line 15.

Downgrading with:
sudo python3 -m pip uninstall cast_control
and
sudo python3 -m pip install cast_control==0.10.11
only works.
Every version between those, breaks with the same output.

Thanks @tomcss for reporting this issue, and thanks @stegrams for providing a solution to it. I'm looking into this, but for the meantime @stegrams's solution might hold you over, as will a more recent version of Python.

solved by
pip install typing-extensions --upgrade

@sbansiheng Thanks very much!

This resolution is impossible. As per https://docs.python.org/3/library/typing.html#typing.TypeAlias:

New in version 3.10.

So to workaround the original exception, one must upgrade Python to at least 3.10

This also occurs using 3.8, the temp solution is not workable

In my case it was incompatible versions of pydantic and django-ninja

In my case the cast_control was not installed.
Thanks @stegrams for the solutions.