Open F1Justin opened 2 weeks ago
提供一下你使用的NB版本号?确实可能是pydantic的版本问题。
版本是2.3.1
按理来说应该没问题() 你把更新pyd后的报错日志给我看看?
看上去似乎是pydantic插件引起的,但是当我把pydantic插件更新后,整个nb项目都无法启动。
`06-19 11:19:56 [ERROR] nonebot | Failed to import "nonebot_plugin_dialectlist" Traceback (most recent call last): File "
", line 14, in File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/load.py", line 131, in load_from_toml return load_all_plugins(plugins, plugin_dirs) File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/load.py", line 65, in load_all_plugins return manager.load_all_plugins() File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 203, in load_all_plugins return set( File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 204, in filter(None, (self.load_plugin(name) for name in self.available_plugins)) File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 167, in load_plugin module = importlib.import_module(self._third_party_plugin_ids[name]) File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "
", line 1204, in _gcd_import File " ", line 1176, in _find_and_load File " ", line 1147, in _find_and_load_unlocked File " ", line 690, in _load_unlocked File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 255, in exec_module super().exec_module(module) File " ", line 940, in exec_module File " ", line 241, in _call_with_frames_removed File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot_plugin_dialectlist/init.py", line 53, in from .config import Config, plugin_config File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot_plugin_dialectlist/config.py", line 3, in from pydantic import BaseModel, field_validator ImportError: cannot import name 'field_validator' from 'pydantic' (/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/pydantic/init.cpython-311-darwin.so) `
这里应该确实是pydantic的问题
按理来说应该没问题() 你把更新pyd后的报错日志给我看看?
报错日志如下
justin@Nitori kag % source /Users/justin/bot/kag/.venv/bin/activate (kag) justin@Nitori kag % pip show pydantic Name: pydantic Version: 1.10.13 Summary: Data validation and settings management using python type hints Home-page: https://github.com/pydantic/pydantic Author: Samuel Colvin Author-email: [s@muelcolvin.com](mailto:s@muelcolvin.com) License: MIT Location: /Users/justin/bot/kag/.venv/lib/python3.11/site-packages Requires: typing-extensions Required-by: fastapi, nonebot-adapter-onebot, nonebot-adapter-qq, nonebot-plugin-apscheduler, nonebot-plugin-localstore, nonebot-plugin-maimaidx, nonebot-plugin-ottohzys, nonebot-plugin-pingti, nonebot-plugin-send-anything-anywhere, nonebot2 (kag) justin@Nitori kag % pip install --upgrade pydantic Requirement already satisfied: pydantic in ./.venv/lib/python3.11/site-packages (1.10.13) Collecting pydantic Downloading pydantic-2.7.4-py3-none-any.whl.metadata (109 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 109.4/109.4 kB 723.9 kB/s eta 0:00:00 Collecting annotated-types>=0.4.0 (from pydantic) Downloading annotated_types-0.7.0-py3-none-any.whl.metadata (15 kB) Collecting pydantic-core==2.18.4 (from pydantic) Downloading pydantic_core-2.18.4-cp311-cp311-macosx_10_12_x86_64.whl.metadata (6.5 kB) Requirement already satisfied: typing-extensions>=4.6.1 in ./.venv/lib/python3.11/site-packages (from pydantic) (4.9.0) Downloading pydantic-2.7.4-py3-none-any.whl (409 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 409.0/409.0 kB 459.8 kB/s eta 0:00:00 Downloading pydantic_core-2.18.4-cp311-cp311-macosx_10_12_x86_64.whl (1.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.9/1.9 MB 2.2 MB/s eta 0:00:00 Downloading annotated_types-0.7.0-py3-none-any.whl (13 kB) Installing collected packages: pydantic-core, annotated-types, pydantic Attempting uninstall: pydantic Found existing installation: pydantic 1.10.13 Uninstalling pydantic-1.10.13: Successfully uninstalled pydantic-1.10.13 ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. nonebot-plugin-ottohzys 0.1.2 requires anyio>=4.0.0, but you have anyio 3.7.1 which is incompatible. nonebot-plugin-ottohzys 0.1.2 requires httpx>=0.25.0, but you have httpx 0.24.1 which is incompatible. nonebot-plugin-ottohzys 0.1.2 requires pydantic<2,>=1.10.4, but you have pydantic 2.7.4 which is incompatible. nonebot-plugin-pingti 0.1.2 requires httpx>=0.26.0, but you have httpx 0.24.1 which is incompatible. nonebot-plugin-pingti 0.1.2 requires pydantic<2,>=1.10.4, but you have pydantic 2.7.4 which is incompatible. nonebot-adapter-qq 1.3.4 requires pydantic<2.0.0,>=1.9.0, but you have pydantic 2.7.4 which is incompatible. nonebot-plugin-picstatus 0.5.7 requires Pillow<10,>=9.2.0, but you have pillow 10.2.0 which is incompatible. nonebot-plugin-maimaidx 0.0.15 requires pydantic<2.0.0,>=1.10.13, but you have pydantic 2.7.4 which is incompatible. nonebot-plugin-emojimix 0.3.1 requires nonebot-plugin-send-anything-anywhere<0.4.0,>=0.3.0, but you have nonebot-plugin-send-anything-anywhere 0.6.1 which is incompatible. Successfully installed annotated-types-0.7.0 pydantic-2.7.4 pydantic-core-2.18.4 (kag) justin@Nitori kag % nb run Using python: /Users/justin/bot/kag/.venv/bin/python 06-19 11:17:36 [SUCCESS] nonebot | NoneBot is initializing... Python-dotenv could not parse statement starting at line 28 Python-dotenv could not parse statement starting at line 29 Python-dotenv could not parse statement starting at line 30 06-19 11:17:36 [INFO] nonebot | Current Env: prod Traceback (most recent call last): File "<string>", line 9, in <module> File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/internal/driver/abstract.py", line 91, in register_adapter self.adapters[name] = adapter(self, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/adapters/onebot/v11/adapter.py", line 71, in init self.onebot_config: Config = get_plugin_config(Config) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/init.py", line 173, in get_plugin_config return type_validate_python(config, model_dump(get_driver().config)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/compat.py", line 212, in type_validate_python return TypeAdapter(type).validate_python(data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/pydantic/type_adapter.py", line 260, in validate_python return self.validator.validate_python(object, strict=strict, from_attributes=from_attributes, context=context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.ValidationError: 1 validation error for Config onebot_access_token Input should be a valid string [type=string_type, input_value=1145141919810, input_type=int] For further information visit https://errors.pydantic.dev/2.7/v/string_type
我也遇到了
首席执行官
这是pydantic 2.0的东西
pydantic_core._pydantic_core.ValidationError: 1 validation error for Config onebot_access_token Input should be a valid string [type=string_type, input_value=1145141919810, input_type=int]
明显指出是 onebot_access_token 输入类型错误,与该插件无关由于目前您的代码无法兼容 pydantic 1.10 版本,与其他插件会有严重的兼容性问题,请考虑在 pyproject.toml 中明确标明 pydantic 的支持版本,使插件可以在安装阶段就能够被依赖管理程序检测并指出冲突,从而避免类似的情况发生
由于目前您的代码无法兼容 pydantic 1.10 版本,与其他插件会有严重的兼容性问题,请考虑在 pyproject.toml 中明确标明 pydantic 的支持版本,使插件可以在安装阶段就能够被依赖管理程序检测并指出冲突,从而避免类似的情况发生
感谢大佬指出问题所在,因为实在想不到如何更改能够在实现 field validators 功能的情况下兼容旧版本的 pydantic ,所以现在已经将把 field validators 删去。
看上去似乎是pydantic插件引起的,但是当我把pydantic插件更新后,整个nb项目都无法启动。
`06-19 11:19:56 [ERROR] nonebot | Failed to import "nonebot_plugin_dialectlist" Traceback (most recent call last): File "", line 14, in
File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/load.py", line 131, in load_from_toml
return load_all_plugins(plugins, plugin_dirs)
File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/load.py", line 65, in load_all_plugins
return manager.load_all_plugins()
File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 203, in load_all_plugins
return set(
File "/Users/justin/bot/kag/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 204, in
filter(None, (self.load_plugin(name) for name in self.available_plugins))