部分初始化模块“pyairtable”

问题描述 投票:0回答:1

基本上,我正在 DJango 上为我工作的地方构建一种数据库管理器。我尝试使用 Airtable 作为数据库(而不是 JSON 或其他方法),因为我们在那里拥有所有信息。但每次我尝试运行该脚本时,它都会给我这个错误

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)
。我安装了正确的软件包,并且尝试查找可能导致此错误的同名文件,但我什么也没找到。为了测试它,我什至为 python 做了这个脚本,但它仍然不起作用


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!")

它仍然给我同样的错误,我尝试通过将其直接粘贴到应用程序上然后使用

os.getenv()
来获取令牌(令牌有权执行airtable表上的所有操作)。我不知道该怎么做才能让它发挥作用。


这是完整的错误回溯:

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)
python python-3.x django database airtable
1个回答
0
投票

这似乎是 Pydantic 版本的上游问题(请参阅此问题)。 要解决此问题,请降级 Pydantic 版本,例如,如果您使用

pip
安装软件包:

python3 -m pip install --upgrade 'pydantic<2.10'
© www.soinside.com 2019 - 2024. All rights reserved.