flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
11.5k stars 449 forks source link

flet==0.25.0.dev3526 apk "Android" pandas error Buffer dtype mismatch, expected 'const int64_t' but got 'long long' #4199

Open jtoror opened 1 month ago

jtoror commented 1 month ago

Duplicate Check

Describe the bug

"Android" apk does not start on physical or simulated devices when requiring the pandas library, throwing error Buffer dtype mismatch, expected 'const int64_t' but got 'long long'

Code sample

Code ```python pyproject.toml [project] name = "amy_app" version = "1.0.0" description = "My first Flet project" authors = [ {name = "John Smith", email = "john@email.com"} ] dependencies = [ "flet==0.25.0.dev3526", "numpy", "pandas" ] # requires-python = ">=3.12" icon = "assets/icon" [tool.flet.android.permission] # --android-permissions "android.permission.INTERNET" = true "android.permission.CAMERA" = true "android.permission.READ_EXTERNAL_STORAGE" = true "android.permission.WRITE_EXTERNAL_STORAGE" = true "android.permission.READ_MEDIA_VISUAL_USER_SELECTED" = true main.py import os import flet as ft import numpy as np import pandas as pd 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 "", line 43, in File "", line 229, in run_module File "", line 88, in _run_code File "/data/user/0/com.flet.amy_app/files/flet/app/main.py", line 4, in import pandas as pd File "/data/user/0/com.flet.amy_app/files/flet/python_site_packages/pandas/init.py", line 49, in from pandas.core.api import ( File "/data/user/0/com.flet.amy_app/files/flet/python_site_packages/pandas/core/api.py", line 1, in from pandas.libs import ( File "/data/user/0/com.flet.amy_app/files/flet/python_site_packages/pandas/libs/init.py", line 18, in from pandas._libs.interval import Interval File "interval.pyx", line 1, in init pandas._libs.interval File "hashtable.pyx", line 1, in init pandas._libs.hashtable File "missing.pyx", line 1, in init pandas.libs.missing File "/data/user/0/com.flet.amy_app/files/flet/python_site_packages/pandas/libs/tslibs/init.py", line 40, in from pandas._libs.tslibs.conversion import localize_pydatetime File "conversion.pyx", line 1, in init pandas._libs.tslibs.conversion File "offsets.pyx", line 1, in init pandas._libs.tslibs.offsets File "timestamps.pyx", line 1, in init pandas._libs.tslibs.timestamps File "tzconversion.pyx", line 55, in init pandas._libs.tslibs.tzconversion ValueError: Buffer dtype mismatch, expected 'const int64_t' but got 'long long'

Expected behavior

No response

Screenshots / Videos

Captures [Upload media here]

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 ```console [Paste your logs here] ```

Additional details

No response

FeodorFitsner commented 1 month ago

Are you getting this error on a physical device (assuming you can't run on a simulator because of shared c++ lib issue)?

If so, what kind of device is that (brand, model)?

jtoror commented 1 month ago

Are you getting this error on a physical device (assuming you can't run on a simulator because of shared c++ lib issue)?

If so, what kind of device is that (brand, model)?

Motorola Moto E5 Plus https://www.gsmarena.com/motorola_moto_e5_plus-9095.php

It's funny because after many days I managed to use Pandas and Matplotlib in an android app using the old way of compiling and it worked

p4a create --requirements numpy,pandas,sqlite3,requests,python-dotenv,matplotlib,cryptography,imagekitio,requests-toolbelt,urllib3 --arch arm64-v8a --arch armeabi-v7a --arch x86_64 --sdk-dir $ANDROID_SDK_ROOT --ndk-dir $ANDROID_SDK_ROOT/ndk/$NDK_VERSION --android-api 33 --ndk-api 21 --color=always --bootstrap=sdl2 --permission INTERNET, WRITE_EXTERNAL_STORAGE --dist-name android

This worked before in physical and virtual.

https://discord.com/channels/981374556059086931/1244027520722931733/1259332729913348136

Now with the dev version and the new flet build it doesn't work. I don't understand why you say something about the shared C++ lib.

FeodorFitsner commented 1 month ago

Pandas is working now in emulator: https://github.com/flet-dev/flet/issues/4203#issuecomment-2427564792

jtoror commented 1 month ago

image

FeodorFitsner commented 1 month ago

What emulator is that? What's host machine/OS, ARM or Intel?

jtoror commented 1 month ago

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

jtoror commented 1 month ago

I deleted my .venv and build folder, created my virtual environment from scratch and created the new build.

FeodorFitsner commented 2 weeks ago

I can't reproduce the issue. What Android SDK is used for emulator?

jtoror commented 2 weeks ago

Hi Feodor, this is driving me crazy, it's a physical phone, with Android Oreo, Cortex-A53 but I have all the libraries running perfectly except pandas. I tried replacing them with other frameworks, but there are no wheels available, so I'm still struggling with pandas, I tried installing pandas==2.0.3 which has 32-bit wheels to see if it would run and I couldn't do it either, since it gives an error when compiling the apk.

On this same phone I have run pandas==2.2.2 with Buildozier and with previous versions of flet using the create command, but with build apk it compiles fine, but gives an error.

jtoror commented 2 weeks ago

It runs without problems on emulator.

jtoror commented 2 weeks ago

I have a tablet with Android 5 and it turns out that the compilation does not run on that abi.

I downloaded and modified the template, changed the SDK to 21 but it did not compile, I got an error when compiling the apk with build apk.

I don't know how to fix this anymore, I need to run pandas.

jtoror commented 2 weeks ago

Code sample

Code ```python import sys import flet as ft from flet.security import encrypt, decrypt import os # import cryptography # import asyncio # from threading import Thread import datetime from babel.dates import format_date, format_datetime, format_time # import sqlite3 # from base64 import b64encode # import requests from dotenv import load_dotenv # import locale # import cv2 # import utils.extras as extras load_dotenv() # print(loc) # print(dir()) def main(page: ft.Page): page.title = "Flet libs test" page.locale_configuration = ft.LocaleConfiguration( supported_locales=[ ft.Locale("es", "VE"), ft.Locale("en", "US") ], current_locale=ft.Locale("es", "VE") ) # page.locale_configuration = ft.Locale("es", "VE") page.scroll = ft.ScrollMode.ADAPTIVE page.padding = 0 page.theme_mode = ft.ThemeMode.DARK page.theme = ft.Theme(font_family="SF Pro Light") # page.theme = ft.Theme( # color_scheme=ft.ColorScheme( # primary=ft.colors.GREY_500, # # primary_container=ft.colors.GREEN_200, # secondary=ft.colors.RED_ACCENT_700, # # secondary_container=ft.colors.GREEN_200, # tertiary=ft.colors.GREEN_ACCENT_700, # # tertiary_container=ft.colors.GREEN_200, # # surface=ft.colors.AMBER_50, # # surface_variant=ft.colors.AMBER_50, # ), # ) # page.bgcolor = ft.colors.SURFACE_VARIANT page.appbar = ft.AppBar(title=ft.Text("PermissionHandler Tests")) ph = ft.PermissionHandler() page.overlay.append(ph) if page.platform == ft.PagePlatform.MACOS: # page.add(ft.CupertinoDialogAction("Cupertino Button")) # print("Macos") pass elif page.platform == ft.PagePlatform.LINUX: # page.window.width = extras.base_width # page.window.height = extras.base_height # o = ph.check_permission(ft.PermissionType.CAMERA) # page.add(ft.Text(f"Checked {ft.PermissionType.CAMERA.name}: {o}")) # page.add(ft.Text("LINUX")) pass elif page.platform == ft.PagePlatform.WINDOWS: # page.window.width = extras.base_width # page.window.height = extras.base_height pass elif page.platform == ft.PagePlatform.ANDROID: # o = ph.check_permission(ft.PermissionType.CAMERA) # page.add(ft.Text(f"Checked {ft.PermissionType.CAMERA.name}: {o}")) # page.add(ft.Text("ANDROID")) # page.window.width = extras.base_width # page.window.height = extras.base_height pass elif page.platform == ft.PagePlatform.IOS: # print("IOS") pass else: # print("Desconocido") pass page.fonts = { "SF Pro Bold": "fonts/SFProText-Bold.ttf", "SF Pro Heavy": "fonts/SFProText-Heavy.ttf", "SF Pro HeavyItalic": "fonts/SFProText-HeavyItalic.ttf", "SF Pro Light": "fonts/SFProText-Light.ttf", "SF Pro Medium": "fonts/SFProText-Medium.ttf", "SF Pro Regular": "fonts/SFProText-Regular.ttf", "SF Pro Semibold": "fonts/SFProText-Semibold.ttf", "SF Pro SemiboldItalic": "fonts/SFProText-SemiboldItalic.ttf", "Poppins ThinItalic": "fonts/poppins/Poppins-ThinItalic.ttf", "Poppins Thin": "fonts/poppins/Poppins-Thin.ttf", "Poppins Semibold": "fonts/poppins/Poppins-Semibold.ttf", "Poppins SemiboldItalic": "fonts/poppins/Poppins-SemiboldItalic.ttf", "Poppins Regular": "fonts/poppins/Poppins-Regular.ttf", "Poppins MediumItalic": "fonts/poppins/Poppins-MediumItalic.ttf", "Poppins Medium": "fonts/poppins/Poppins-Medium.ttf", "Poppins LightItalic": "fonts/poppins/Poppins-LightItalic.ttf", "Poppins Light": "fonts/poppins/Poppins-Light.ttf", "Poppins Italic": "fonts/poppins/Poppins-Italic.ttf", "Poppins ExtraLightItalic": "fonts/poppins/Poppins-ExtraLightItalic.ttf", "Poppins ExtraLight": "fonts/poppins/Poppins-ExtraLight.ttf", "Poppins ExtraBold": "fonts/poppins/Poppins-ExtraBold.ttf", "Poppins ExtraBoldItalic": "fonts/poppins/Poppins-ExtraBoldItalic.ttf", "Poppins BoldItalic": "fonts/poppins/Poppins-BoldItalic.ttf", "Poppins Bold": "fonts/poppins/Poppins-Bold.ttf", "Poppins BlackItalic": "fonts/poppins/Poppins-BlackItalic.ttf", "Poppins Black": "fonts/poppins/Poppins-Black.ttf", } con_string = os.getenv("IK_URL") # print(conString) page.add(ft.Text(f'env {con_string}')) def change_date(e): # print(e) # print(f"Date picker changed, value is {date_picker.value}") page.add(ft.Text(f"Date picker changed, value is {date_picker.value}")) def date_picker_dismissed(e): # print(f"Date picker dismissed, value is {date_picker.value}") page.add( ft.Text(f"Date picker dismissed, value is {date_picker.value}")) today = datetime.datetime.now().date() next_year = today + datetime.timedelta(days=365) date_picker = ft.DatePicker( on_change=change_date, on_dismiss=date_picker_dismissed, first_date=today, last_date=next_year, ) page.overlay.append(date_picker) date_button = ft.ElevatedButton( "Pick date", icon=ft.icons.CALENDAR_MONTH, on_click=lambda _: date_picker.pick_date(), ) page.add(date_button) def check_permission(e): o = ph.check_permission(e.control.data) page.add(ft.Text(f"Checked {e.control.data.name}: {o}")) def request_permission(e): o = ph.request_permission(e.control.data) page.add(ft.Text(f"Requested {e.control.data.name}: {o}")) def open_app_settings(e): o = ph.open_app_settings() page.add(ft.Text(f"App Settings: {o}")) 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: page.add(ft.Text("1")) from pandas import DataFrame page.add(ft.Text("2")) df = DataFrame( [("alpha", 1), ("bravo", 2), ("charlie", 3)], columns=["Letter", "Number"], ) page.add(ft.Text("3")) assert df.to_csv() == ( ",Letter,Number\n" "0,alpha,1\n" "1,bravo,2\n" "2,charlie,3\n" ) page.add(ft.Text("4")) page.add(ft.Text("pandas: test_basic - OK")) except Exception as e: page.add(ft.Text("5")) page.add(ft.Text(f"pandas: test_basic - error: {e}")) test_basic() def matPlot_tests(e): def test_basic(): try: from supabase import create_client, Client import matplotlib import matplotlib.pyplot as plt from flet.matplotlib_chart import MatplotlibChart # from imagekitio import ImageKit # import plotly.express as px # from PIL import Image matplotlib.use("svg") fig, ax = plt.subplots() fruits = ['apple', 'blueberry', 'cherry', 'orange'] counts = [40, 100, 30, 55] bar_labels = ['red', 'blue', '_red', 'orange'] bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange'] ax.bar(fruits, counts, label=bar_labels, color=bar_colors) ax.set_ylabel('fruit supply') ax.set_title('Fruit supply by kind and color') ax.legend(title='Fruit color') page.add(MatplotlibChart(fig, expand=True)) page.add(ft.Text("matPlot: test_basic - OK")) except Exception as e: page.add(ft.Text(f"matPlot: test_basic - error: {e}")) test_basic() def supa_tests(e): def test_basic(): try: from supabase import create_client, Client url: str = "https://jhkhjkhj.supabase.co" key: str = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.." supabase: Client = create_client(url, key) response = supabase.table("countries").select( "*").limit(1).execute() page.add(ft.Text("supa: test_basic - OK")) page.add(ft.Text(response)) except Exception as e: page.add(ft.Text(f"supa: test_basic - error: {e}")) test_basic() def pil_tests(e): def test_basic(): try: import PIL from PIL import Image # Location of the image img = Image.open("assets/icon.png") pilv = PIL.__version__ # size of the image # print(img.size) # format of the image # print(img.format) page.add(ft.Text("PIL: test_basic - OK")) page.add(ft.Text(img.size)) page.add(ft.Text(pilv)) except Exception as e: page.add(ft.Text(f"PIL: test_basic - error: {e}")) test_basic() def cryptography_tests(e): def test_basic(): try: secret_key = "MY_APP_SECRET_KEY" plain_text = "This is a secret message!" encrypted_data = encrypt(plain_text, secret_key) descrypted_data = decrypt(encrypted_data, secret_key) page.add(ft.Text("cryptography: test_basic - OK")) page.add(ft.Text(plain_text)) page.add(ft.Text(encrypted_data)) page.add(ft.Text(descrypted_data)) except Exception as e: page.add(ft.Text(f"PIL: test_basic - error: {e}")) test_basic() def datetime_tests(e): def test_basic(): try: fecha_ahora = datetime.datetime.now() fecha_formateada = fecha_ahora.strftime( "%A, %d de %B de %Y a las %H:%M").capitalize() page.add(ft.Text(fecha_formateada)) d = datetime.date(2007, 4, 1) # format_date(d, locale='en') format_date = format_datetime( fecha_ahora, "EEEE ',' dd 'de' MMMM 'de' yyyy 'a las' hh:mm", locale="es") page.add(ft.Text(f'babel {format_date.capitalize()}')) # locale.setlocale(locale.LC_ALL, ('es_VE.UTF-8', 'UTF-8')) # loc = locale.getlocale() # page.add(ft.Text(f'get {loc}')) # locale.setlocale(locale.LC_ALL, '') # loc = locale.getlocale() # page.add(ft.Text(f'set {loc}')) # fecha_formateada = fecha_ahora.strftime( # "%A, %d de %B de %Y a las %H:%M").capitalize() # page.add(ft.Text(fecha_formateada)) # page.add(ft.Text("datetime: test_basic - OK 1")) # locale.setlocale(locale.LC_ALL, ('es', 'UTF-8')) # fecha_formateada = fecha_ahora.strftime( # "%A, %d de %B de %Y a las %H:%M").capitalize() # page.add(ft.Text(fecha_formateada)) # page.add(ft.Text("datetime: test_basic - OK 2")) except Exception as e: page.add(ft.Text(f"datetime: test_basic - error: {e}")) test_basic() page.add( ft.SafeArea( ft.Column( [ ft.ResponsiveRow( [ ft.ElevatedButton( "Run datetime tests", on_click=datetime_tests, # col={"xs": 12, "sm": 6, "md": 3}, col={"xs": 6, "sm": 6, "md": 3}, ), ft.ElevatedButton( "Run cryptography tests", on_click=cryptography_tests, col={"xs": 6, "sm": 6, "md": 3}, ), ft.ElevatedButton( "Run Numpy tests", on_click=numpy_tests, # col={"xs": 12, "sm": 6, "md": 3}, col={"xs": 6, "sm": 6, "md": 3}, ), ft.ElevatedButton( "Run Pandas tests", on_click=pandas_tests, col={"xs": 6, "sm": 6, "md": 3}, ), ft.ElevatedButton( "Run pil tests", on_click=pil_tests, col={"xs": 6, "sm": 6, "md": 3}, ), ft.ElevatedButton( "Run MatPlot tests", on_click=matPlot_tests, col={"xs": 6, "sm": 6, "md": 3}, ), ft.ElevatedButton( "Run Supa tests", on_click=supa_tests, col={"xs": 6, "sm": 6, "md": 3}, ) ] ), ft.ResponsiveRow( [ ft.OutlinedButton( "Check Camera Permission", data=ft.PermissionType.CAMERA, on_click=check_permission, col={"xs": 6}, ), ft.OutlinedButton( "Request Camera Permission", data=ft.PermissionType.CAMERA, on_click=request_permission, col={"xs": 6}, ) ] ), ft.ResponsiveRow( [ ft.OutlinedButton( "Check STORAGE Permission", data=ft.PermissionType.STORAGE, # ok aplly settings on_click=check_permission, col={"xs": 6}, ), ft.OutlinedButton( "Request STORAGE Permission", data=ft.PermissionType.STORAGE, on_click=request_permission, col={"xs": 6}, ) ] ), ft.ResponsiveRow( [ ft.OutlinedButton( "Check MEDIA_LIBRARY Permission", data=ft.PermissionType.MEDIA_LIBRARY, # ok on Default on_click=check_permission, col={"xs": 6}, ), ft.OutlinedButton( "Request MEDIA_LIBRARY Permission", data=ft.PermissionType.MEDIA_LIBRARY, on_click=request_permission, col={"xs": 6}, ) ] ), ft.ResponsiveRow( [ ft.OutlinedButton( "Open App Settings", on_click=open_app_settings, col={"xs": 12}, ) ] ) ] ) ) ) ft.app(target=main, assets_dir="assets") '''
jtoror commented 2 weeks ago

Code sample

Code ```python [project] name = "anumpy_app" version = "1.0.0" description = "" requires-python = ">=3.12" authors = [ {name = "Jon", email = "jt@gmail.com"} ] dependencies = [ "flet==0.25.0.dev3526", "cryptography", "python-dotenv", "requests", "numpy==2.1.1", "pandas==2.2.2", "matplotlib==3.9.2", "supabase", "pillow", "babel" ] [tool.flet.android.permission] # --android-permissions "android.permission.INTERNET" = true "android.permission.CAMERA" = true [tool.flet] template.ref = "0.25.0-dev" android.adaptive_icon_background = "#ffffff" split_per_abi = false app.exclude = [ ".venv", ".vscode", "build", "template", "temp", ] # --exclude [tool.flet.splash] color = "#222222" # --splash-color dark_color = "#222222" # --splash-dark-color web = true # --no-web-splash ios = true # --no-ios-splash android = true # --no-android-splash [tool.flet.compile] # app = false # packages = false cleanup = true # template.dir = "/home/dev/dev_code/linux/flet/gym_new/template" # template.ref = "0.25.0-dev" # "opencv-python", '''
jtoror commented 2 weeks ago

Another local thing is that it doesn't translate the dates into my local language. I had to install Babel.

FeodorFitsner commented 2 weeks ago

I don't know what Android SDK does Kivy target (used by Buldozer), but Flet is targeting SDK 34 which is Android 14+: https://apilevels.com/

This is forced by Google. You cannot upload your app to Google Play if it's not targeting Android 14 (API level 34): https://developer.android.com/google/play/requirements/target-sdk

jtoror commented 2 weeks ago

It's correct but I need an apk that won't be on Google Play

jtoror commented 2 weeks ago

but the error seems to me to be due to the 64-bit architecture but as I said it had already worked before.

jtoror commented 2 weeks ago

https://discord.com/channels/981374556059086931/1247163952186654790/1259855990849929217

jtoror commented 2 weeks ago

I don't know what Android SDK does Kivy target (used by Buldozer), but Flet is targeting SDK 34 which is Android 14+: https://apilevels.com/

This is forced by Google. You cannot upload your app to Google Play if it's not targeting Android 14 (API level 34): https://developer.android.com/google/play/requirements/target-sdk

image

FeodorFitsner commented 2 weeks ago

Alright, it's 32-bit OS. I will take a look, when have a moment, what might be wrong with pandas package on that platform.

jtoror commented 2 weeks ago

Alright, it's 32-bit OS. I will take a look, when have a moment, what might be wrong with pandas package on that platform.

Thank you very much, friend, I'll be waiting, a hug.