flet
flet copied to clipboard
flet build macos with numpy - built app crashes
Description Building Flet app with numpy completes with no error on mac, but built app crashes right after opening a window.
Code example to reproduce the issue:
import flet as ft
import numpy as np
def main(page: ft.Page):
page.add(
ft.Text(f'Value: {np.random.random_sample()}')
)
ft.app(target=main)
Build command:
flet build macos
Describe the results you received:
Built app crashes right after rendering a window.
Running the app by python main.py or flet run main.py works fine.
After commenting import numpy as np out, built app renders a window with no content. It won't crash.
Describe the results you expected:
Random float something like Value: 0.8875341508950007 appears on a window.
Additional information you deem important (e.g. issue happens only occasionally):
App built by flet pack main.py won't crash and works as expected.
Flet version (pip show flet):
Name: flet
Version: 0.21.2
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/handsome/Documents/Python/fletAudioPlayback/.venv/lib/python3.11/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):
numpy
Operating system:
ProductName: macOS ProductVersion: 14.3.1 BuildVersion: 23D60
M2 Max 12 core CPU + 30 core GPU 32GB RAM
Additional environment details:
% python --version
Python 3.11.7
% pip list|grep numpy
numpy 1.26.4
% flutter --version
Flutter 3.19.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ba39319843 (2 weeks ago) • 2024-03-07 15:22:21 -0600
Engine • revision 2e4ba9c6fb
Tools • Dart 3.3.1 • DevTools 2.31.1
% brew list cocoapods
Warning: Treating cocoapods as a formula. For the cask, use homebrew/cask/cocoapods or specify the `--cask` flag.
/opt/homebrew/Cellar/cocoapods/1.15.2/bin/pod
/opt/homebrew/Cellar/cocoapods/1.15.2/bin/xcodeproj
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/bin/ (5 files)
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/cache/ (34 files)
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/doc/ (11485 files)
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/extensions/ (4 files)
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/ (2166 files)
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/specifications/ (34 files)
% xcodebuild -version
Xcode 15.3
Build version 15E204a
I can reproduce this issue by simply adding the numpy import to a hello world file.
Works:
import flet as ft
def main(page: ft.Page):
page.add(ft.Text("Hello World!"))
ft.app(main)
Fails with crash after build:
import flet as ft
import numpy as np
def main(page: ft.Page):
page.add(ft.Text("Hello World!"))
ft.app(main)
As the reporter noted, this causes a crash, after which point, all apps in this project will render a blank page (no crash), even if you remove the dependency.
The app works with flet run and even flet pack suggesting there may be an issue with flet build.
Related: https://github.com/flet-dev/serious-python/issues/85
There is an explanation and workaround for "numpy on macos" issue: https://github.com/flet-dev/serious-python/issues/85#issuecomment-2065000974
Either re-build the app with flet build macos (both 0.21.2 and 0.22.0 build templates where updated to set OPENBLAS_NUM_THREADS variable or implement a fix in your own python app.
Great! Thank you, @FeodorFitsner ! I just tested building my app with 0.21.1 and 0.22.0 without modifying my code, and both built apps worked with no issue. Awesome!