unionai-oss / unionai-oss/pandera

Pyinstaller build fails when using pydantic version 2.*

Open
#1,663 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
4.5k
Forks
453
Avg merge
4d 6h
Merged PRs (30d)
19

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Windows failure with the Python 3.10.6, pydantic 2.7.2, pandera 0.19.3, and PyInstaller 6.7.0 commands in the issue. Then inspect pandera/decorators.py and the generated executable behavior; done means the provided test_pandera.py binary runs without the missing pydantic.deprecated.decorator error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.