semmyk-research
semmyk-research

Reputation: 389

PyGWalker: cannot import name 'Field' from 'pydantic'

pygwalker was installed with: (streamlit) c:\XxX\Anaconda3>conda install -c conda-forge pygwalker (15 Aug '23)

import pygwalker as pyg threw an ImportError, shown at the end of this question.

question: how can one resolve this?

Looking through the file structure, the following was noted. In "C:\XxX\Anaconda3\envs\streamlit\Lib\site-packages\pydantic_init_.py"

from .fields import Required
from .main import BaseConfig, BaseModel, create_model, validate_model

In "C:\XxX\Anaconda3\envs\streamlit\Lib\site-packages\pydantic\main.py"

from .fields import Field

and in "C:\XxX\Anaconda3\envs\streamlit\Lib\site-packages\pydantic\fields.py"

class Field:
    __slots__ = (
                ... ... )

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
File <timed exec>:7

File c:\XxX\Anaconda3\envs\streamlit\Lib\site-packages\pygwalker\__init__.py:14
     11 __version__ = "0.2.1"
     12 __hash__ = __rand_str()
---> 14 from pygwalker.api.walker import walk
     15 from pygwalker.api.gwalker import GWalker
     16 from pygwalker.api.html import to_html

File c:\XxX\Anaconda3\envs\streamlit\Lib\site-packages\pygwalker\api\walker.py:6
      2 import inspect
      4 from typing_extensions import Literal
----> 6 from .pygwalker import PygWalker
      7 from pygwalker.data_parsers.base import FieldSpec, BaseDataParser
      8 from pygwalker._typing import DataFrame

File c:\XxX\Anaconda3\envs\streamlit\Lib\site-packages\pygwalker\api\pygwalker.py:19
     13 from pygwalker.services.tip_tools import TipOnStartTool
     14 from pygwalker.services.render import (
     15     render_gwalker_html,
     16     render_gwalker_iframe,
     17     get_max_limited_datas
     18 )
---> 19 from pygwalker.services.preview_image import PreviewImageTool, render_preview_html, ChartData
     20 from pygwalker.services.upload_data import (
     21     BatchUploadDatasToolOnWidgets,
     22     BatchUploadDatasToolOnJupyter
     23 )
     24 from pygwalker.services.spec import get_spec_json

File c:\XxX\Anaconda3\envs\streamlit\Lib\site-packages\pygwalker\services\preview_image.py:4
      1 from typing import Optional, List, Dict
      3 from jinja2 import Environment, PackageLoader
----> 4 from pydantic import BaseModel, Field
      6 from pygwalker.utils.display import display_html
      9 jinja_env = Environment(
     10     loader=PackageLoader("pygwalker"),
     11     autoescape=(()),  # select_autoescape()
     12 )

ImportError: cannot import name 'Field' from 'pydantic' (c:\XxX\Anaconda3\envs\streamlit\Lib\site-packages\pydantic\__init__.py)

PS: This is somewhat related but doesn't resolve the problem - Why i can't import BaseModel from Pydantic?

Upvotes: 1

Views: 1165

Answers (1)

semmyk-research
semmyk-research

Reputation: 389

After much troubleshooting, the error got resolved by updating to pygwalker==0.3.2.


Incidentally, conda install -c conda-forge pygwalker installed pygwalker==0.2.1, which was not apparent to me when I posted this question. Why conda did not install the pygwalker==0.3.2 from conda-forge, I do not know!

I tried editing ...Lib\site-packages\pydantic\__init__.py, to from .fields import Required, Field, which moved me past the import error but got stuck with other errors.
Finally, I got pygwalker installed via pip install pygwalker==0.3.2 and pydantic updated.

PS: I've since raised an issue on pygwalker GitHub. The issue with conda was acknowledge and a minor update made to version 0.3.2.

Upvotes: 1

Related Questions