python / typing_extensions

Backported and experimental type hints for Python
Other
446 stars 110 forks source link

ImportError: cannot import name 'TypeAliasType' from 'typing_extensions' #369

Closed anusonawane closed 7 months ago

anusonawane commented 7 months ago

I'm encountering an ImportError while trying to import TypeAliasType from typing_extensions. Here's the traceback:

from darts import TimeSeries
  from darts.models import RandomForest, LinearRegressionModel

File "/home/env/lib/python3.11/site-packages/darts/utils/utils.py", line 13, in <module>
    from IPython import get_ipython

...
File "/home/env/lib/python3.11/site-packages/IPython/core/guarded_eval.py", line 40, in <module>
    from typing_extensions import TypeAliasType

ImportError: cannot import name 'TypeAliasType' from 'typing_extensions' (/home/env/lib/python3.11/site-packages/typing_extensions.py)

This error seems to be occurring within the context of the Darts library, specifically when importing TypeAliasType from typing_extensions. However, it appears that TypeAliasType is not present in the typing_extensions module.

I'm using Python 3.11 and have the following relevant packages installed:

u8darts: 0.18.0 IPython: 8.23.0 typing-extensions:4.5.0

Could someone please provide guidance on how to resolve this issue?

Thank you for your help!

### Tasks
AlexWaygood commented 7 months ago

This error is occurring because IPython is trying to import TypeAliasType from typing_extensions, but typing_extensions.TypAliasType does not exist in your environment. This is because TypeAliasType was first added to typing_extensions in v4.6.0, but you have v4.5.0 installed in your environment.

IPython declares that it requires typing_extensions>=4.6.0, though, so I'm not immediately sure how you have the older version of typing_extensions installed alongside it: https://github.com/ipython/ipython/blob/fe52b206ecd0e566fff935fea36d26e0903ec34b/pyproject.toml#L35

AlexWaygood commented 7 months ago

Ah, it seems like this issue is a duplicate of https://github.com/ipython/ipython/issues/14380, which was fixed last week in https://github.com/ipython/ipython/pull/14381

AlexWaygood commented 7 months ago

Okay, it seems like this is a bug in IPython's packaging, which has already been fixed on their main branch; the fix will presumably be included in the next IPython release. For now, you should be able to workaround the issue by installing typing_extensions>=4.6 into your environment. (If you're using a requirements.txt, constraints.txt or pyproject.toml file, you should just be able to add a typing_extensions>=4.6 pin to one of them.)

Hope that helps! :-)