I have faced a similar error message. What has fixed it for me was to add hidden imports.
With the following hidden imports that problem went away:
pyinstaller --hidden-import=pydantic --hidden-import=pydantic-core --hidden-import=pydantic.deprecated.decorator app.py