flet
flet copied to clipboard
flet==0.25.0.dev3526 "Android" Apk Does not run with Numpy "Emulator"
Duplicate Check
- [X] I have searched the opened issues and there are no duplicates
Describe the bug
"Android" Apk Does not run with Numpy "Emulator"
Code sample
Code
pyproject.toml
[project]
name = "amy_app"
version = "1.0.0"
description = "My first Flet project"
authors = [
{name = "John Smith", email = "[email protected]"}
]
dependencies = [
"flet==0.25.0.dev3526",
"numpy",
"pandas",
"imagekitio",
"supabase",
"Pillow",
"libjpeg",
"plotly"
]
main.py
import os
import flet as ft
import numpy as np
import pandas as pd
from imagekitio import ImageKit
from supabase import create_client, Client
from PIL import Image
import plotly.express as px
def main(page: ft.Page):
page.title = "Flet counter example"
page.vertical_alignment = ft.MainAxisAlignment.CENTER
txt_number = ft.TextField(
value="0", text_align=ft.TextAlign.RIGHT, width=100)
def minus_click(e):
txt_number.value = str(int(txt_number.value) - 1)
page.update()
def plus_click(e):
txt_number.value = str(int(txt_number.value) + 1)
page.update()
page.add(
ft.Row(
[
ft.IconButton(ft.icons.REMOVE, on_click=minus_click),
txt_number,
ft.IconButton(ft.icons.ADD, on_click=plus_click),
],
alignment=ft.MainAxisAlignment.CENTER,
)
)
ft.app(main)
To reproduce
Traceback (most recent call last):
File "/data/user/0/com.flet.amy_app/files/flet/python_site_packages/numpy/_core/init.py", line 23, in
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/data/user/0/com.flet.amy_app/files/flet/python_site_packages/numpy/init.py", line 114, in
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
- The Python version is: Python3.12 from ""
- The NumPy version is: "2.1.1"
and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help.
Original error was: dlopen failed: library "libc++_shared.so" not found: needed by /data/data/com.flet.amy_app/files/flet/python_site_packages/numpy/_core/_multiarray_umath.cpython-312.so in namespace classloader-namespace
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "
Expected behavior
No response
Screenshots / Videos
Captures
Operating System
Linux
Operating system details
Kubuntu 24.04
Flet version
0.25.0.dev3526
Regression
No, it isn't
Suggestions
No response
Logs
Logs
[Paste your logs here]
Additional details
No response
libc++_shared.so has been added to Flet's Python distro and I've got both Numpy and Pandas working in Android Emulator - see recording below. Will test on a real device later.
I'm running on Resizable_Experimental_API_34.
https://github.com/user-attachments/assets/bdca8e21-0f71-43b7-bb5e-f9444423642d
App code:
import flet as ft
def main(page: ft.Page):
page.title = "Flet libs test"
def numpy_tests(e):
def test_basic():
try:
from numpy import array
assert (array([1, 2]) + array([3, 5])).tolist() == [4, 7]
page.add(ft.Text("numpy: test_basic - OK"))
except Exception as e:
page.add(ft.Text(f"numpy: test_basic - error: {e}"))
def test_performance():
try:
from time import time
import numpy as np
start_time = time()
SIZE = 500
a = np.random.rand(SIZE, SIZE)
b = np.random.rand(SIZE, SIZE)
np.dot(a, b)
# With OpenBLAS, the test devices take at most 0.4 seconds. Without OpenBLAS, they take
# at least 1.0 seconds.
duration = time() - start_time
page.add(
ft.Text(f"numpy: test_performance - OK, duration: {duration:.3f}")
)
print(f"{duration:.3f}")
assert duration < 0.7
except Exception as e:
page.add(ft.Text(f"numpy: test_performance - error: {e}"))
test_basic()
test_performance()
def pandas_tests(e):
def test_basic():
try:
from pandas import DataFrame
df = DataFrame(
[("alpha", 1), ("bravo", 2), ("charlie", 3)],
columns=["Letter", "Number"],
)
assert df.to_csv() == (
",Letter,Number\n" "0,alpha,1\n" "1,bravo,2\n" "2,charlie,3\n"
)
page.add(ft.Text("pandas: test_basic - OK"))
except Exception as e:
page.add(ft.Text(f"pandas: test_basic - error: {e}"))
test_basic()
page.add(
ft.SafeArea(
ft.Column(
[
ft.ElevatedButton("Run Numpy tests", on_click=numpy_tests),
ft.ElevatedButton("Run Pandas tests", on_click=pandas_tests),
]
)
)
)
ft.app(main)
pyproject.toml:
[project]
name = "numpy_app"
version = "1.0.0"
description = ""
authors = [
{name = "Flet Developer", email = "[email protected]"}
]
dependencies = ["flet==0.25.0.dev3526", "numpy", "pandas"]
[tool.flet]
template.ref = "0.25.0-dev"
android.adaptive_icon_background = "#ffffff"
[tool.poetry]
name = "my_app"
version = "1.0.0"
description = "My first Flet project"
authors = ["Feodor Fitsner"]
[tool.poetry.dependencies]
python = "^3.8"
flet = "0.25.0.dev3526"
numpy = "^2.0.0"
pandas = "^2.2.2"
What emulator is that? What's host machine/OS, ARM or Intel?
What emulator is that? What's host machine/OS, ARM or Intel?
On my phone a MOTOe5 plus https://www.gsmarena.com/motorola_moto_e5_plus-9095.php
host Intel x64
I deleted my .venv and build folder, created my virtual environment from scratch and created the new build.
Will check on a real device tomorrow.
Will check on a real device tomorrow.
I just tried it on the emulator and it works. But it doesn't work on my physical device. Tomorrow I'll try it on a tablet to see if it works. Thanks.
I've just tried on Galaxy Tab A8 (SM X200) and it worked. It runs on Android 13.0
I also uploaded my APK it case you want to test it on your phone: https://github.com/FeodorFitsner/flet/releases/download/downloads/app-release.apk
OK, I've just tested on a real phone with Android 14 and then on emulator with Android 8 and both numpy and pandas worked:
OK, I've just tested on a real phone with Android 14 and then on emulator with Android 8 and both numpy and pandas worked:
Thanks Feodor, it's likely that my phone has something strange, the PIL error doesn't let me advance in my project, another thing is it possible that the first execution of the apk after installing it takes less time than it currently takes on physical devices?
I'm working on PIL issue, thanks for your patience. Re: first time run - will be looking into that too.
PIL has been fixed. I cannot reproduce errors from this issue.