alexdelorenzo / cast_control

📺 Control Chromecasts from Linux and D-Bus
https://cast.firstbyte.dev
Other
480 stars 8 forks source link

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

Open tomcss opened 2 years ago

tomcss commented 2 years ago

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)
stegrams commented 2 years ago

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.

stegrams commented 2 years ago

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.

alexdelorenzo commented 1 year ago

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.

sbansiheng commented 1 year ago

solved by pip install typing-extensions --upgrade

imozart987 commented 1 year ago

@sbansiheng Thanks very much!

btbroot commented 1 year ago

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

Rohith-sreedharan commented 11 months ago

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

rtviii commented 9 months ago

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

BharatPanera commented 7 months ago

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

doubleZ0108 commented 1 month ago

In my case, the previous author from IPython import embed but none of the usage. I comment this import to avoid the issue.