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

Pyinstaller build fails when using pydantic version 2.* #1663

Open
3 tasks done
kunalgupta02209 opened this issue May 30, 2024 · 0 comments
Open
3 tasks done

Pyinstaller build fails when using pydantic version 2.* #1663

kunalgupta02209 opened this issue May 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@kunalgupta02209
Copy link

Describe the bug
After creating a Pyinstaller build, I'm facing the following Error when I try to run the binary:

Traceback (most recent call last):
  File "pydantic\_internal\_validators.py", line 98, in _import_string_logic    
  File "importlib\__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, 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 61, in import_string
  File "pydantic\_internal\_validators.py", line 107, 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 "test_pandera.py", line 1, in <module>
    import pandera as pa
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked   
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module     
  File "pandera\__init__.py", line 27, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked   
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module     
  File "pandera\decorators.py", line 26, in <module>
  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
  File "pydantic\__init__.py", line 386, in __getattr__
  File "pydantic\_migration.py", line 287, in wrapper
  File "pydantic\_internal\_validators.py", line 63, in import_string
pydantic_core._pydantic_core.PydanticCustomError: Invalid python path: No module named 'pydantic.deprecated.decorator'
[1007164] Failed to execute script 'test_pandera' due to unhandled exception!
  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandera.
  • (optional) I have confirmed this bug exists on the main branch of pandera.

Code Sample, a copy-pastable example

The Temp.zip contains the poetry environment that can be used to quickly reproduce the bug.
Temp.zip

Further steps to reproduce from scratch:

pip install pydantic==2.7.2
pip inatall pandera==0.19.3
pip install pyinstaller==6.7.0

Add a file that just imports pandera called test_pandera.py
eg:

import pandera as pa
if __name__ == "__main__":
    print(pa)

Execute Pyinstaller script to generate binary.

python -m pyinstaller --noconfirm --onefile --name TestPandera --distpath ./dist/Pandera ./test_pandera.py

Run the executable:

./dist/Pandera/TestPandera.exe

Expected behavior

The executable should execute without the above error. This error also does not pop up when the script is executed in a python environment.

Desktop (please complete the following information):

  • Version: 0.19.3
  • Python version 3.10.6.
  • OS = Windows 11
  • Poetry package manager = 1.8..2 (can be irrelevant in this case)

Additional context

I did try to investigate why this was occurring and came across an import in pandera/decorators.py from pydantic (from pydantic import validate_arguments)
This seems to not have any source definition in the current version of pydantic and after some digging seems to have been deprecated on outright replaces in version 2.x of pydantic (can't find the source for this).
I did locate the alternative which should be from pydantic import validate_call in the latest master of pydantic source code.

@kunalgupta02209 kunalgupta02209 added the bug Something isn't working label May 30, 2024
kunalgupta02209 added a commit to kunalgupta02209/pandera that referenced this issue May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant