flet icon indicating copy to clipboard operation
flet copied to clipboard

No module named 'pydantic' on android

Open ismlsmile opened this issue 9 months ago • 3 comments

Duplicate Check

  • [x] I have searched the opened issues and there are no duplicates

Describe the bug

I have a project using 0.27.6. I successfully run using command "flet run --android", and the app does well on android. But when I use "flet build apk" to build an apk file and install on the phone, when I run it, the app crashed: Traceback (most recent call last): File "", line 95, in File "", line 229, in run_module File "", line 88, in _run_code File "/data/user/0/com.mycompany.alldetail/files/flet/app/main.py", line 3, in from app.app import App, AppConfig File "/data/user/0/com.mycompany.alldetail/files/flet/app/app/app.py", line 5, in from .config.config import AppConfig File "/data/user/0/com.mycompany.alldetail/files/flet/app/app/config/config.py", line 5, in from pydantic import BaseModel, Field ModuleNotFoundError: No module named 'pydantic'

Should I do some extra config to include pydantic?

Code sample

Code
[Paste your code here]

To reproduce

flet build apk

Expected behavior

No response

Screenshots / Videos

Captures

[Upload media here]

Operating System

macOS

Operating system details

android

Flet version

0.27.6

Regression

No, it isn't

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

ismlsmile avatar Mar 23 '25 01:03 ismlsmile

Share your build config, and verbose (--v) logs.

ndonkoHenri avatar Mar 23 '25 01:03 ndonkoHenri

demo project that can reproduce this problem: https://github.com/ismlsmile/flet-demo

ismlsmile avatar Mar 23 '25 12:03 ismlsmile

I gave the latest pre-release a try and it worked. You can leave the version constrain on pydantic unspecified and the latest supported version will be picked. Please give it a try and let know how it works out.

src/main.py
import flet as ft
import pydantic


def main(page: ft.Page):
    page.vertical_alignment = ft.MainAxisAlignment.CENTER
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    page.add(ft.Text(f"Pydantic version: {pydantic.__version__}", size=30))


ft.run(main)
pyproject.toml
dependencies = [
    "flet >=0.70.0.dev0",
    "pydantic",
]

[dependency-groups]
dev = [
    "flet[all] >=0.70.0.dev0",
]

[tool.uv]
prerelease = "allow"

[tool.flet.app]
path = "src"
Screenshot

after running the app with flet debug

Image

ndonkoHenri avatar Dec 16 '25 23:12 ndonkoHenri