flet icon indicating copy to clipboard operation
flet copied to clipboard

Torch `bin` not packaged with `flet build macos`

Open torablien opened this issue 10 months ago • 15 comments

When packaging an app for macOS (arm) with torch, the app builds but when launched, it gives a white screen with the error RuntimeError: Unable to find torch_shm_manager at /Users/admin/Library/Caches/flet_testing-1.0.0-1/app/__pypackages__/torch/bin/torch_shm_manager

If you manually copy the bin directory from your local torch install (e.g. flet-testing/venv/lib/python3.12/site-packages/torch/bin to Library/Caches/flet_testing-1.0.0-1/app/__pypackages__/torch) then the app runs as expected.

Code example to reproduce the issue:

import flet as ft
import torch

def main(page: ft.Page):
    page.add(ft.Text("Hello World!"))

ft.app(main)

App displays a blank white screen for 10 seconds (splash screen loading?) and then shows a white screen with the following error:

Traceback (most recent call last):
  File "<string>", line 43, in <module>
  File "<frozen runpy>", line 229, in run_module
  File "<frozen runpy>", line 88, in _run_code
  File "/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempgFfj8Q/main.py", line 5, in <module>
  File "/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempgFfj8Q/__pypackages__/torch/__init__.py", line 1427, in <module>
  File "/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempgFfj8Q/__pypackages__/torch/__init__.py", line 1416, in manager_path
RuntimeError: Unable to find torch_shm_manager at /Users/admin/Library/Caches/flet_testing-1.0.0-1/app/__pypackages__/torch/bin/torch_shm_manager

Describe the results you expected:

App runs and shows Hello World

Additional information you deem important (e.g. issue happens only occasionally):

Once bin is copied over, it works as expected. Although, IIUC flet build does not use pyinstaller, this might be helpful: https://github.com/pytorch/pytorch/issues/1898

Flet version (pip show flet):

% pip show flet
Name: flet
Version: 0.22.0
Summary: Flet for Python - easily build interactive multi-platform apps in Python
Home-page: 
Author: Appveyor Systems Inc.
Author-email: [email protected]
License: Apache-2.0
Location: /Users/admin/Code/flet-testing2/venv/lib/python3.12/site-packages
Requires: cookiecutter, fastapi, flet-runtime, packaging, qrcode, uvicorn, watchdog
Required-by: 

Give your requirements.txt file (don't pip freeze, instead give direct packages):

flet
torch

Operating system:

M1 Pro Mac - OS X Sonoma 14.1.2

Additional environment details:

Python 3.12.2

torablien avatar Apr 19 '24 19:04 torablien

Could you share your full build log please?

FeodorFitsner avatar Apr 19 '24 20:04 FeodorFitsner

Nevermind, I see "bin" directories are stripped off from the resulting installation.

FeodorFitsner avatar Apr 19 '24 20:04 FeodorFitsner

Is there a fix for this, without manually manipulating the caches folder?

In the Flet build.py, I can't see where the bin directories are being filtered out, or an argument to specify specific folders to include.

I need to distribute an executable, and I am struggling to come up with an elegant way of doing it (ie. zero user interaction).

ap4499 avatar Aug 29 '24 13:08 ap4499