marcelotduarte / cx_Freeze

cx_Freeze creates standalone executables from Python scripts, with the same performance, is cross-platform and should work on any platform that Python itself works on.
https://marcelotduarte.github.io/cx_Freeze/
Other
1.31k stars 214 forks source link

Prisma Python is missing binaries when frozen in CI but not locally #2509

Open ntindle opened 1 month ago

ntindle commented 1 month ago

Discussed in https://github.com/marcelotduarte/cx_Freeze/discussions/2504

Originally posted by **ntindle** July 15, 2024 When I freeze the Prisma python package as part of my CI using GitHub Actions, it has an error when run locally: ``` PS C:\Users\nicka> agpt_server.exe Traceback (most recent call last): File "C:\Users\runneradmin\AppData\Local\pypoetry\Cache\virtualenvs\autogpt-server-Hzddpd5Y-py3.10\src\cx_Freeze\cx_Freeze\initscripts\__startup__.py", line 141, in run File "C:\Users\runneradmin\AppData\Local\pypoetry\Cache\virtualenvs\autogpt-server-Hzddpd5Y-py3.10\src\cx_Freeze\cx_Freeze\initscripts\console.py", line 25, in run File "autogpt_server\app.py", line 46, in File "autogpt_server\app.py", line 34, in main File "autogpt_server\app.py", line 26, in run_processes File "autogpt_server\app.py", line 22, in run_processes File "D:\a\AutoGPT\AutoGPT\rnd\autogpt_server\autogpt_server\util\process.py", line 50, in start File "D:\a\AutoGPT\AutoGPT\rnd\autogpt_server\autogpt_server\util\process.py", line 28, in execute_run_command File "D:\a\AutoGPT\AutoGPT\rnd\autogpt_server\autogpt_server\util\service.py", line 64, in run File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\asyncio\base_events.py", line 649, in run_until_complete File "D:\a\AutoGPT\AutoGPT\rnd\autogpt_server\autogpt_server\data\db.py", line 10, in connect File "C:\Users\runneradmin\AppData\Local\pypoetry\Cache\virtualenvs\autogpt-server-Hzddpd5Y-py3.10\lib\site-packages\prisma\_base_client.py", line 430, in connect File "C:\Users\runneradmin\AppData\Local\pypoetry\Cache\virtualenvs\autogpt-server-Hzddpd5Y-py3.10\lib\site-packages\prisma\engine\_query.py", line 349, in connect File "C:\Users\runneradmin\AppData\Local\pypoetry\Cache\virtualenvs\autogpt-server-Hzddpd5Y-py3.10\lib\site-packages\prisma\engine\_query.py", line 58, in _ensure_file File "C:\Users\runneradmin\AppData\Local\pypoetry\Cache\virtualenvs\autogpt-server-Hzddpd5Y-py3.10\lib\site-packages\prisma\engine\utils.py", line 111, in ensure prisma.engine.errors.BinaryNotFoundError: Expected C:\Users\nicka\prisma-query-engine-windows.exe, C:\Users\nicka\.cache\prisma-python\binaries\5.11.0\efd2449663b3d73d637ea1fd226bafbcf45b3102\prisma-query-engine-windows.exe or C:\Users\runneradmin\.cache\prisma-python\binaries\5.11.0\efd2449663b3d73d637ea1fd226bafbcf45b3102\node_modules\prisma\query-engine-windows.exe to exist but none were found or could not be executed. Try running prisma py fetch ``` Repro Steps and far more details here: https://github.com/ntindle/cx_freeze_prisma_reproduction It is worth pointing out you MUST build in ci (or another PC), as your paths will be valid from the poetry install in the repo once you run cx_freeze.
marcelotduarte commented 1 month ago

I'll try to look at it over the weekend, I'm busy these days.

ntindle commented 1 month ago

Much appreciated. I got pretty out of my depth with it

marcelotduarte commented 1 month ago

I think you were close to figuring out how to solve the issue when you described it in https://github.com/RobertCraigie/prisma-client-py/issues/976

Then rename query-engine-windows.exe to prisma-query-engine-windows.exe in prisma/node_modules/prisma

You have to copy this file next to the executable, or in the case of cx_Freeze, use include_files.

Find out how to get the 'binary cache dir' that is shown in the command prisma py version, and use it like

include_files.append(("{binary cache dir}/node_modules/prisma/query-engine-windows.exe", "prisma-query-engine-windows.exe"))

marcelotduarte commented 1 month ago

Please test the possibly solution at https://github.com/ntindle/cx_freeze_prisma_reproduction/pull/2 to close the issue.