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

flet build macos with numpy - built app crashes #2932

Closed
tokyohandsome opened this issue Mar 23, 2024 · 4 comments
Closed

flet build macos with numpy - built app crashes #2932

tokyohandsome opened this issue Mar 23, 2024 · 4 comments
Labels
bug Something isn't working has-upstream This issue depends on an upstream issue packaging Related to app packaging

Comments

@tokyohandsome
Copy link

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: hello@flet.dev
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

@torablien
Copy link

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.

@FeodorFitsner
Copy link
Contributor

Related: flet-dev/serious-python#85

@ndonkoHenri ndonkoHenri added bug Something isn't working packaging Related to app packaging labels Apr 17, 2024
@FeodorFitsner
Copy link
Contributor

There is an explanation and workaround for "numpy on macos" issue: flet-dev/serious-python#85 (comment)

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.

@tokyohandsome
Copy link
Author

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!

@ndonkoHenri ndonkoHenri added the has-upstream This issue depends on an upstream issue label Nov 25, 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 has-upstream This issue depends on an upstream issue packaging Related to app packaging
Projects
None yet
Development

No branches or pull requests

4 participants