Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

加载插件时报错 #52

Open
syvshc opened this issue Nov 18, 2024 · 2 comments
Open

加载插件时报错 #52

syvshc opened this issue Nov 18, 2024 · 2 comments

Comments

@syvshc
Copy link

syvshc commented Nov 18, 2024

环境如下:
Windows 11
python 3.12.4
nb-cli 1.4.2

Failed to import "nonebot_plugin_what2eat"
Traceback (most recent call last):
  File "<string>", line 12, in <module>
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\load.py", line 131, in load_from_toml
    return load_all_plugins(plugins, plugin_dirs)
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\load.py", line 65, in load_all_plugins
    return manager.load_all_plugins()
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\manager.py", line 203, in load_all_plugins
    return set(
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\manager.py", line 204, in <genexpr>
    filter(None, (self.load_plugin(name) for name in self.available_plugins))
> File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\manager.py", line 167, in load_plugin
    module = importlib.import_module(self._third_party_plugin_ids[name])
  File "D:\ProgramData\miniconda3\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\manager.py", line 255, in exec_module
    super().exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot_plugin_what2eat\__init__.py", line 12, in <module>
    from nonebot_plugin_apscheduler import scheduler
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot_plugin_apscheduler\__init__.py", line 7, in <module>
    from .config import Config
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot_plugin_apscheduler\config.py", line 1, in <module>
    from pydantic import Field, BaseSettings
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\pydantic\__init__.py", line 402, in __getattr__
    return _getattr_migration(attr_name)
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\pydantic\_migration.py", line 296, in wrapper
    raise PydanticImportError(
pydantic.errors.PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.9/migration/#basesettings-has-moved-to-pydantic-settings for more details.

For further information visit https://errors.pydantic.dev/2.9/u/import-error

看起来是一个库的问题, 想问一下怎么解决, 谢谢大大

@syvshc
Copy link
Author

syvshc commented Nov 18, 2024

简单定位了一下问题, what2eat 要求 nonebot_plugin_apscheduler==0.2.0, 这个版本里用的是

from pydantic import Field, BaseSettings

但是自动安装的 2.9.2 的 pydantic 已经把 BaseSettings 放到了 pydantic-setting 模块里:
https://docs.pydantic.dev/2.9/migration/#moved-in-pydantic-v2

@syvshc
Copy link
Author

syvshc commented Nov 18, 2024

我手动安装 1.10.19 的 pydantic 后报错

11-18 14:46:53 [ERROR] nonebot | Failed to import "nonebot_plugin_what2eat"
Traceback (most recent call last):
  File "<string>", line 12, in <module>
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\load.py", line 131, in load_from_toml
    return load_all_plugins(plugins, plugin_dirs)
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\load.py", line 65, in load_all_plugins
    return manager.load_all_plugins()
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\manager.py", line 203, in load_all_plugins
    return set(
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\manager.py", line 204, in <genexpr>
    filter(None, (self.load_plugin(name) for name in self.available_plugins))
> File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\manager.py", line 167, in load_plugin
    module = importlib.import_module(self._third_party_plugin_ids[name])
  File "D:\ProgramData\miniconda3\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\manager.py", line 255, in exec_module
    super().exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot_plugin_what2eat\__init__.py", line 17, in <module>
    require("nonebot_plugin_apscheduler")
  File "C:\Users\syvshc-lily\qqbot\.venv\Lib\site-packages\nonebot\plugin\load.py", line 188, in require
    raise RuntimeError(f'Cannot load plugin "{name}"!')
RuntimeError: Cannot load plugin "nonebot_plugin_apscheduler"!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant