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.2k stars 431 forks source link

Flet can't run certain libraries #4213

Open useless21 opened 1 day ago

useless21 commented 1 day ago

Duplicate Check

Describe the bug

I'm trying to get scikit-learn to run but it causes an error. All other libraries are running fine. It runs well in my ide but once compiled causes an error. So far I have tested for Windows, android and webapp. The windows is executable when packaged with pyInstaller. Hope this error can be sorted out 1729592055864

Code sample

import flet as flt from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.metrics.pairwise import cosine_similarity import pandas as pd

Function to tokenize the code (a simple example)

def myapp(page: flt.Page):

Initialise page criteria and components

page.theme_mode = flt.ThemeMode.LIGHT
page.window.maximized=True
page.scroll=True

global methods, method1, data1, cl1, runner,allowed
allowed=["py"]
runner = 0
file_picker = flt.FilePicker()
page.overlay.append(file_picker)

# dv = flt.Column([methods], scroll=True)
# meth = flt.Row([dv], scroll=True, expand=1, vertical_alignment=flt.CrossAxisAlignment.START)
# method1 =
data1 = flt.TextField(
    label="Code 1",
    value="""

def factorial(n):
if n == 0 or n == 1: return 1 else: return n * factorial(n - 1)

Example usage

num = 5 result = factorial(num) print(f"The factorial of {num} is {result}")",""", hint_text="eg. 12 14 15 18 24...", helper_text="Original Code", tooltip="Enter integers separated by spaces", multiline=True, width=(page.width-50)/2, ) cl1 = flt.TextField( label="Code 2", value="""
def sum_of_squares(numbers): total = 0 for num in numbers: total += num * num return total

Example usage

nums = [1, 2, 3, 4, 5] result = sum_of_squares(nums) print(f"The sum of squares of {nums} is {result}")""", hint_text="eg. 8", helper_text="Code to be checked", tooltip="Enter a single integer for cache line number", multiline=True, width=(page.width-50) / 2, )

butang = flt.ElevatedButton(text="Run", on_click=lambda e: process())

# methods.horizontal_lines = flt.border.BorderSide(2, "#fdfcff")
page.add(butang)

# Function to compute the plagiarism similarity between two code snippets
def compute_similarity(code1, code2):
    # Tokenize both code snippets
    code1_tokens = code1
    code2_tokens = code2

    # Use TF-IDF Vectorizer to convert code to vectors
    vectorizer = TfidfVectorizer()
    vect_mat=vectorizer.fit_transform([code1_tokens, code2_tokens])
    print("TF-IDF Vocabulary:")
    print(vectorizer.vocabulary_)
    df = pd.DataFrame(vectorizer.transform([code1_tokens, code2_tokens]).toarray(), columns=vectorizer.get_feature_names_out())
    print(df)
    # Compute the cosine similarity between the vectors
    similarity_matrix = cosine_similarity(vect_mat)
    print(similarity_matrix)
    return similarity_matrix[0][1]  # Returns the similarity score between code1 and code2

def process():
    row=0
    mastlst=[]
    tbllst = []
    for i in range(2):
        for j in range(i + 1, 2):
            tbllst.insert(0,"Code 1")
            tbllst.insert(1,"Code 2")
            #Compare logic TFIDF
            similarity_score=compute_similarity(data1.value, cl1.value)
            print(f"Plagiarism Similarity Score: {similarity_score:.2f}")
            tbllst.insert(2,round(similarity_score, 2))
            print(row)

    mastlst.append(tbllst)
    page.update()

flt.app(target=myapp)

To reproduce

Compile the code using flet build apk

Expected behavior

image

Screenshots / Videos

Captures [Upload media here]

Operating System

Windows

Operating system details

Windows 10

Flet version

0.24.1

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs ```console Microsoft Windows [Version 10.0.19045.5011] (c) Microsoft Corporation. All rights reserved. (Code Plagiarism) C:\Users\user\PycharmProjects\Code Plagiarism>flet build apk --verbose [18:24:07] Flutter bootstrap directory: C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78 No additional Flutter dependencies! [18:24:13] Created Flutter bootstrap project from gh:flet-dev/flet-build-template with ref 0.24.1 ✅ Customized app icons and splash images ✅ Run subprocess: ['C:\\Users\\user\\dev\\flutter\\bin\\dart.BAT', 'run', 'flutter_launcher_icons'] ( ● ) Generating app icons ⏳... The Dart CLI developer tool uses Google Analytics to report usage and diagnostic data along with package dependencies, and crash reporting to send basic crash reports. This data is used to help improve the Dart platform, Flutter framework, and related tools. Telemetry is not sent on the very first run. To disable reporting of telemetry, run this terminal command: dart --disable-analytics If you opt out of telemetry, an opt-out event will be sent, and then no further information will be sent. This data is collected in accordance with the Google Privacy Policy (https://policies.google.com/privacy). ( ● ) Generating app icons(3.8s) ( ● ) Generating app icon(15.3s) Got dependencies in `C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78`. ( ● ) Generating app icons(7.2s) Built flutter_launcher_icons:flutter_launcher_icons. (● ) Generating app icons ⏳... ════════════════════════════════════════════ FLUTTER LAUNCHER ICONS (v0.13.1) ════════════════════════════════════════════ ( ● ) Generating app icons ⏳... • Creating default icons Android ( ● ) Generating app icons ⏳... • Overwriting the default Android launcher icon with a new icon ( ● ) Generating app icons ⏳... • Overwriting default iOS launcher icon with new icon ( ● ) Generating app icons ⏳... Creating Icons for Web... ( ● ) Generating app icons ⏳... Creating Icons for Windows... ( ● ) Generating app icons ⏳... Creating Icons for MacOS... ( ● ) Generating app icons ⏳... ✓ Successfully generated launcher icons [18:24:42] Generated app icons ✅ Run subprocess: ['C:\\Users\\user\\dev\\flutter\\bin\\dart.BAT', 'run', 'flutter_native_splash:create'] ( ● ) Generating splash screens ⏳... Built flutter_native_splash:create. ( ● ) Generating splash screens ⏳... [Android] Creating default splash images ( ● ) Generating splash screens ⏳... [Android] Creating dark mode splash images ( ● ) Generating splash screens ⏳... [Android] Creating default android12splash images ( ● ) Generating splash screens ⏳... [Android] Creating dark mode android12splash images ( ● ) Generating splash screens ⏳... [Android] Updating launch background(s) with splash image path... [Android] - android/app/src/main/res/drawable/launch_background.xml ( ● ) Generating splash screens ⏳... [Android] - android/app/src/main/res/drawable-night/launch_background.xml [Android] - android/app/src/main/res/drawable-v21/launch_background.xml [Android] - android/app/src/main/res/drawable-night-v21/launch_background.xml [Android] Updating styles... [Android] - android/app/src/main/res/values-v31/styles.xml [Android] No android/app/src/main/res/values-v31/styles.xml found in your Android project [Android] Creating android/app/src/main/res/values-v31/styles.xml and adding it to your Android project [Android] - android/app/src/main/res/values-night-v31/styles.xml [Android] No android/app/src/main/res/values-night-v31/styles.xml found in your Android project [Android] Creating android/app/src/main/res/values-night-v31/styles.xml and adding it to your Android project [Android] - android/app/src/main/res/values/styles.xml [Android] - android/app/src/main/res/values-night/styles.xml [iOS] Creating images (● ) Generating splash screens ⏳... [iOS] Creating dark mode images ( ● ) Generating splash screens ⏳... [iOS] Updating ios/Runner/Info.plist for status bar hidden/visible ( ● ) Generating splash screens ⏳... [Web] Creating images ( ● ) Generating splash screens ⏳... [Web] Creating images ( ● ) Generating splash screens ⏳... [Web] Creating background images [Web] Creating CSS ( ●) Generating splash screens ⏳... [Web] Updating index.html ( ● ) Generating splash screens ⏳... ✅ Native splash complete. Now go finish building something awesome! � You rock! �� Like the package? Please give it a � here: https://pub.dev/packages/flutter_native_splash [18:24:47] Generated splash screens ✅ Run subprocess: ['C:\\Users\\user\\dev\\flutter\\bin\\dart.BAT', 'run', 'serious_python:main', 'package', 'C:\\Users\\user\\PycharmProjects\\Code Plagiarism', '--mobile', '--platform', 'mobile', '--dep-mappings', 'flet=flet-embed', '--req-deps', 'flet-embed', '--exclude', 'build'] ( ● ) Packaging Python app ⏳... Built serious_python:main. ( ●) Packaging Python app ⏳... Running package command Creating asset directory: C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78\app Copying Python app from C:\Users\user\PycharmProjects\Code Plagiarism to C:\Users\user\AppData\Local\Temp\serious_python_temp550ed4d2 ( ● ) Packaging Python app ⏳... Configured mobile platform with sitecustomize.py at C:\Users\user\AppData\Local\Temp\serious_python_sitecustomizec4a1ebb\sitecustomize.py Installing dependencies [flet-embed] with pip command to C:\Users\user\AppData\Local\Temp\serious_python_temp550ed4d2\__pypackages__ Extracting Python distributive from C:\Users\user\AppData\Local\Temp\cpython-3.11.6+20231002-x86_64-pc-windows-msvc-shared-install_only.tar.gz to C:\Users\user\AppData\Local\Temp\hostpython3.11_c63394f4 (● ) Packaging Python app ⏳... Compiling Python sources at C:\Users\user\AppData\Local\Temp\serious_python_temp550ed4d2 ( ● ) Packaging Python app ⏳... Delete unnecessary files with extensions: [.py, .c, .h, .typed, .exe, .so, .a, .pdb, .pyd, .dll] Delete unnecessary files and directories: [__pycache__, bin] ( ●) Packaging Python app ⏳... Creating app archive at C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78\app/app.zip from C:\Users\user\AppData\Local\Temp\serious_python_temp550ed4d2 ( ● ) Packaging Python app ⏳... Deleting temp directory C:\Users\user\AppData\Local\Temp\serious_python_temp550ed4d2 ( ● ) Packaging Python app ⏳... Deleting sitecustomize directory C:\Users\user\AppData\Local\Temp\serious_python_sitecustomizec4a1ebb Deleting Python directory C:\Users\user\AppData\Local\Temp\hostpython3.11_c63394f4 [18:25:27] Packaged Python app ✅ Run subprocess: ['C:\\Users\\user\\dev\\flutter\\bin\\flutter.BAT', 'build', 'apk'] ( ● ) Building .apk for Android ⏳... ( ● ) Building .apk for Android ⏳... ( ● ) Building .apk for Android ⏳... characters 1.3.0 (1.3.1 available) collection 1.18.0 (1.19.1 available) fl_chart 0.68.0 (0.69.0 available) flutter_launcher_icons 0.13.1 (0.14.1 available) flutter_lints 2.0.3 (5.0.0 available) http_parser 4.0.2 (4.1.1 available) js 0.6.7 (0.7.1 available) lints 2.1.1 (5.1.0 available) material_color_utilities 0.11.1 (0.12.0 available) meta 1.15.0 (1.16.0 available) ! package_info_plus 8.1.0 (overridden) path 1.9.0 (1.9.1 available) screen_retriever 0.1.9 (0.2.0 available) sensors_plus 4.0.2 (6.1.0 available) sensors_plus_platform_interface 1.2.0 (2.0.0 available) serious_python 0.7.1 (0.8.1 available) serious_python_android 0.7.1 (0.8.1 available) serious_python_darwin 0.7.1 (0.8.1 available) serious_python_linux 0.7.1 (0.8.1 available) serious_python_platform_interface 0.7.1 (0.8.1 available) serious_python_windows 0.7.1 (0.8.1 available) toml 0.15.0 (0.16.0 available) url_strategy 0.2.0 (discontinued) ! wakelock_plus 1.2.8 (overridden) ! web 1.1.0 (overridden) web_socket_channel 2.4.5 (3.0.1 available) window_manager 0.3.9 (0.4.2 available) Got dependencies! 1 package is discontinued. 24 packages have newer versions incompatible with dependency constraints. Try `flutter pub outdated` for more information. ( ● ) Building .apk for Android ⏳... Font asset "CupertinoIcons.ttf" was tree-shaken, reducing it from 257628 to 209160 bytes (18.8% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app. Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 1261080 bytes (23.3% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app. C:/Users/user/AppData/Local/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/bin/llvm-strip.exe: error: 'C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78\build\serious_python_android\intermediates\merg ed_native_libs\release\mergeReleaseNativeLibs\out\lib\arm64-v8a\libpythonbundle.so': The file was not recognized as a valid object file ( ● ) Building .apk for Android ⏳... C:/Users/user/AppData/Local/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/bin/llvm-strip.exe: error: 'C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78\build\s erious_python_android\intermediates\merged_native_libs\release\mergeReleaseNativeLibs\out\lib\armeabi-v7a\libpythonbundle.so': The file was not recognized as a valid object file C:/Users/user/AppData/Local/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/bin/llvm-strip.exe: error: 'C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78\build\serious_python_android\intermediates\merg ed_native_libs\release\mergeReleaseNativeLibs\out\lib\x86_64\libpythonbundle.so': The file was not recognized as a valid object file C:/Users/user/AppData/Local/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/bin/llvm-strip.exe: error: 'C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78\build\app\intermediates\merged_native_libs\rele ase\mergeReleaseNativeLibs\out\lib\arm64-v8a\libpythonbundle.so': The file was not recognized as a valid object file C:/Users/user/AppData/Local/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/bin/llvm-strip.exe: error: 'C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78\build\app\intermediates\merged_native_libs\rele ase\mergeReleaseNativeLibs\out\lib\armeabi-v7a\libpythonbundle.so': The file was not recognized as a valid object file C:/Users/user/AppData/Local/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/bin/llvm-strip.exe: error: 'C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78\build\app\intermediates\merged_native_libs\rele ase\mergeReleaseNativeLibs\out\lib\x86_64\libpythonbundle.so': The file was not recognized as a valid object file ( ● ) Building .apk for Andro 173.4s ( ● ) Building .apk for Android ⏳... √ Built build\app\outputs\flutter-apk\app-release.apk (65.4MB) [18:28:30] Built .apk for Android ✅ Copying build output from: C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78\build\app\outputs\flutter-apk\* Copied build to build\apk directory ✅ Deleting Flutter bootstrap directory C:\Users\user\AppData\Local\Temp\flet_flutter_build_R9NKOXIa78 [18:28:34] Successfully built your .apk for Android! � Find it in build\apk directory. � ```

Additional details

No response

OwenMcDonnell commented 1 day ago

Can you please re-format your code sample for readability, and also try this sample with the latest Flet release?

useless21 commented 13 hours ago

Can you please re-format your code sample for readability, and also try this sample with the latest Flet release?

I have updated the codes to only the parts where sk-learn is used and updated flet to the latest version (0.24.1). The issue still persists