adamerose / PandasGUI

A GUI for Pandas DataFrames
MIT No Attribution
3.17k stars 229 forks source link

Cannot import name 'Literal' from 'typing' [Fix Also Included] #159

Closed kaustubhgupta closed 3 years ago

kaustubhgupta commented 3 years ago

Describe the bug
While importing the module, I am getting errors.

Command Run: from pandasgui import show

Error:

ImportError: cannot import name 'Literal' from 'typing'

image

Environment OS: Windows 10 Python: 3.7.6 IDE: VSCode

Package versions

ipython==7.25.0
ipython-genutils==0.2.0
pandasgui==0.2.12
plotly==5.1.0
PyQt5==5.15.4
PyQt5-sip==12.9.0
PyQtWebEngine==5.15.4

Solution I found As per the StackOverflow answer, typing.Literal is only available from Python 3.8 and up.

I tested this and found that it actually works in Python 3.8.10 without any errors but shows the import error in Python 3.7.6. image

Therefore, following the answer, I found that typing_extensions can easily solve this error. In pandasgui < widgets < json_viewer.py: https://github.com/adamerose/PandasGUI/blob/db78e86c066bf2144bf0e7da90449097c87cb07a/pandasgui/widgets/json_viewer.py#L2

try:
    from typing import Literal
except ImportError:
    from typing_extensions import Literal

I replaced did this replacement and it worked in Python 3.7.6

adamerose commented 3 years ago

Fixed in #163

HongLouyemeng commented 1 year ago

Describe the bug While importing the module, I am getting errors.

Command Run: from pandasgui import show

Error:

ImportError: cannot import name 'Literal' from 'typing'

image

Environment OS: Windows 10 Python: 3.7.6 IDE: VSCode

Package versions

ipython==7.25.0
ipython-genutils==0.2.0
pandasgui==0.2.12
plotly==5.1.0
PyQt5==5.15.4
PyQt5-sip==12.9.0
PyQtWebEngine==5.15.4

Solution I found As per the StackOverflow answer, typing.Literal is only available from Python 3.8 and up.

I tested this and found that it actually works in Python 3.8.10 without any errors but shows the import error in Python 3.7.6. image

Therefore, following the answer, I found that typing_extensions can easily solve this error. In pandasgui < widgets < json_viewer.py:

https://github.com/adamerose/PandasGUI/blob/db78e86c066bf2144bf0e7da90449097c87cb07a/pandasgui/widgets/json_viewer.py#L2

try:
    from typing import Literal
except ImportError:
    from typing_extensions import Literal

I replaced did this replacement and it worked in Python 3.7.6

Nice work!