flet-dev / serious-python

Python runtime for Flutter apps
Apache License 2.0
212 stars 22 forks source link

I couldn't start Flask Application with 3rd party library #62

Closed brkeudunman closed 10 months ago

brkeudunman commented 10 months ago

I have used Flask example for quick look if I can import them. However I came across with that issue.

from flask import Flask, request
from contextlib import redirect_stdout
from io import StringIO

from PIL import Image
import torch
import os
import torch.nn as nn
from torchvision import transforms
from torchvision.models import mobilenet_v2

port = 55001

print("Trying to run a socket server on:", port)

class PythonRunner:
    __globals = {}
    __locals = {}
    ...

Issue:

...
W/DartWorker(11970): type=1400 audit(0.0:352): avc:  granted  { execute } for  path="/data/data/com.example.flask_example/app_flutter/flask_example-1.0.0-1/python_bundle/modules/_datetime.cpython-311.so" dev="dm-38" ino=352478 scontext=u:r:untrusted_app_32:s0:c182,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c182,c256,c512,c768 tclass=file app=com.example.flask_example
D/EGL_emulation(11970): app_time_stats: avg=22.60ms min=4.45ms max=182.76ms count=33
I/flutter (11970): after Py_Finalize
I/flutter (11970): Error running Python program

I have updated the requirements.txt as

Flask==3.0.0
numpy==1.24.3
torch==2.0.1
torchvision==0.15.2
Pillow==10.0

Note: I tried to comment libraries and try each library for import(for example; # import torch) and every one of them is making a problem.

brkeudunman commented 10 months ago

I have already checked that issue -> https://github.com/flet-dev/serious-python/issues/44

FeodorFitsner commented 10 months ago

Both numpy and pillow are netive packages. Please see this guide for including them into your mobile app: https://github.com/flet-dev/serious-python?tab=readme-ov-file#adding-custom-python-libraries

In the context of Flet: https://flet.dev/docs/guides/python/packaging-app-for-distribution#native-python-packages