我用 pyinstaller 编译了代码以生成 .exe,但是当我启动它时,它告诉我找不到模块“pydantic.deprecated.decorator”。 这似乎合乎逻辑,因为我对这个名字一无所知。所以我不知道该怎么做才能解决这个问题
我已经尝试重新安装 pydantic
Traceback (most recent call last):
File "pydantic\_internal\_validators.py", line 99, in _import_string_logic
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pydantic.deprecated.decorator'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "pydantic\_internal\_validators.py", line 62, in import_string
File "pydantic\_internal\_validators.py", line 108, in _import_string_logic
ImportError: No module named 'pydantic.deprecated.decorator'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "UX.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
File "RAG_modif_pour_UX.py", line 18, in <module>
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
File "langchain_ollama\__init__.py", line 3, in <module>
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
File "langchain_ollama\chat_models.py", line 39, in <module>
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
File "langchain_core\tools\__init__.py", line 22, in <module>
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
File "langchain_core\tools\base.py", line 27, in <module>
File "<frozen importlib._bootstrap>", line 1229, in _handle_fromlist
File "pydantic\__init__.py", line 402, in __getattr__
File "pydantic\_migration.py", line 287, in wrapper
File "pydantic\_internal\_validators.py", line 64, in import_string
pydantic_core._pydantic_core.PydanticCustomError: Invalid python path: No module named 'pydantic.deprecated.decorator'
我也遇到过类似的错误消息。对我来说解决这个问题的是添加隐藏的导入。
通过以下隐藏导入,问题就消失了:
pyinstaller --hidden-import=pydantic --hidden-import=pydantic-core --hidden-import=pydantic.deprecated.decorator app.py