关于Nonebot2插件 ModuleNotFoundError: No module named ‘requests‘
错误报告如下:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/python3/lib/python3.8/multiprocessing/spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/usr/local/python3/lib/python3.8/multiprocessing/spawn.py", line 125, in _main
prepare(preparation_data)
File "/usr/local/python3/lib/python3.8/multiprocessing/spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "/usr/local/python3/lib/python3.8/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "/usr/local/python3/lib/python3.8/runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "/usr/local/python3/lib/python3.8/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/local/python3/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/www/qq_bot/nonebot2_bot/bot.py", line 34, in <module>
nonebot.load_plugins("nonebot2_bot/plugins")
File "/www/qq_bot/nonebot2_bot/.venv/lib/python3.8/site-packages/nonebot/plugin/load.py", line 50, in load_plugins
return manager.load_all_plugins()
File "/www/qq_bot/nonebot2_bot/.venv/lib/python3.8/site-packages/nonebot/plugin/manager.py", line 176, in load_all_plugins
return set(
File "/www/qq_bot/nonebot2_bot/.venv/lib/python3.8/site-packages/nonebot/plugin/manager.py", line 177, in <genexpr>
filter(None, (self.load_plugin(name) for name in self.available_plugins))
> File "/www/qq_bot/nonebot2_bot/.venv/lib/python3.8/site-packages/nonebot/plugin/manager.py", line 146, in load_plugin
module = importlib.import_module(
File "/usr/local/python3/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "/www/qq_bot/nonebot2_bot/.venv/lib/python3.8/site-packages/nonebot/plugin/manager.py", line 242, in exec_module
super().exec_module(module)
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/www/qq_bot/nonebot2_bot/nonebot2_bot/plugins/dream_remind_s/__init__.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
上述错误信息中包含两个位置的两个python3.8。
其中/www/qq_bot/nonebot2_bot/.venv/lib/python3.8的python3.8缺少requests模块
为此需要单独给其安装requests模块
# /www/qq_bot/nonebot2_bot/.venv/lib/python3.8/bin/pip install requests
问题以外的隐蔽。由于/www/qq_bot/nonebot2_bot/.venv/lib/python3.8
路径下的python并非我安装的,且并不存在于以往版本的nonebot2中,导致第一时间并没有注意到关键问题,排查过程以外的耗时,特此记录。