pythonpython-3.xdjangodatabaseairtable

Partially initialized module 'pyairtable'


Basically I am bulding a sort of database manager on DJango for the place I work for. I am trying to use airtable as the database (Instead of a JSON or other methods) because we have all the information there. But everytime I try to run the script, it gives me this error AttributeError: partially initialized module 'pyairtable' from 'C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyairtable\__init__.py' has no attribute 'api' (most likely due to a circular import). I have the propper packages installed, and I tried looking for a file with the same name that could cause this error, but I found nothing. To test it I even did this script for python and it still does not work


from pyairtable import Table
from dotenv import load_dotenv, find_dotenv

AT = os.getenv(AIRTABLE_TOKEN)
BI = os.getenv(BASE_ID)

RC_table = Table(AT, BI, 'RC')
LB_table = Table(AT, BI, 'L&B')
PM_table = Table(AT, BI, 'PM')
print("Table imported and initialized successfully!")

And it still gives me the same error, I have tried to get the token by pasting it directly on the app and then using the os.getenv() (the token has access to do everything on the airtable tables). I don't know what to do to make it work.


This is the full error traceback:

Traceback (most recent call last):
  File "C:\Users\PC\Desktop\teat.py", line 1, in <module>
    from pyairtable import Table
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyairtable\__init__.py", line 3, in <module>
    from .api import Api, Base, Table
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyairtable\api\__init__.py", line 1, in <module>
    from .api import Api
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyairtable\api\api.py", line 9, in <module>
    from pyairtable.api.enterprise import Enterprise
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyairtable\api\enterprise.py", line 8, in <module>
    from pyairtable.models._base import AirtableModel, rebuild_models
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyairtable\models\__init__.py", line 17, in <module>
    from .comment import Comment
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyairtable\models\comment.py", line 10, in <module>
    class Comment(
    ...<58 lines>...
        reactions: List["Reaction"] = pydantic.Field(default_factory=list)
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pydantic\_internal\_model_construction.py", line 221, in __new__
    set_model_fields(cls, bases, config_wrapper, ns_resolver)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pydantic\_internal\_model_construction.py", line 593, in set_model_fields
    fields, class_vars = collect_model_fields(cls, bases, config_wrapper, ns_resolver, typevars_map=typevars_map)
                         ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pydantic\_internal\_fields.py", line 112, in collect_model_fields
    type_hints = _typing_extra.get_cls_type_hints(cls, ns_resolver=ns_resolver, lenient=True)
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pydantic\_internal\_typing_extra.py", line
 472, in get_cls_type_hints
    hints[name] = eval_type(value, globalns, localns, lenient=lenient)
                  ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pydantic\_internal\_typing_extra.py", line
 498, in eval_type
    return eval_type_backport(value, globalns, localns)
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pydantic\_internal\_typing_extra.py", line
 534, in eval_type_backport
    return _eval_type_backport(value, globalns, localns, type_params)
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pydantic\_internal\_typing_extra.py", line
 558, in _eval_type_backport
    return _eval_type(value, globalns, localns, type_params)
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pydantic\_internal\_typing_extra.py", line
 588, in _eval_type
    return typing._eval_type(  # type: ignore
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
        value, globalns, localns, type_params=type_params
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\typing.py", line 474, in _eval_type
    return t._evaluate(globalns, localns, type_params, recursive_guard=recursive_guard)
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\typing.py", line 1081, in _evaluate
    eval(self.__forward_code__, globalns, localns),
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 1, in <module>
AttributeError: partially initialized module 'pyairtable' from 'C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyairtable\__init__.py' has no attribute 'api' (most likely due to a circular import)

Solution

  • This seems to be an upstream issue with the Pydantic version (see this issue). To work around it, downgrade your Pydantic version, for example, if you use pip to install packages:

    python3 -m pip install --upgrade 'pydantic<2.10'