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.6k stars 455 forks source link

`flet build` creates bundle but running it gives `ImportError: No module named main` error #4444

Closed OmarBelfeki closed 2 days ago

OmarBelfeki commented 3 days ago

Duplicate Check

Describe the bug

Traceback (most recent call last): File "", line 47, in File "", line 222, in run_module File "", line 142, in _get_module_details ImportError: No module named main

Code sample

Code ```python print(error) ```

To reproduce

...

Expected behavior

No response

Screenshots / Videos

Captures ![Screenshot_2024-11-28-23-36-20-36_92b64b2a7aa6eb3771ed6e18d0029815](https://github.com/user-attachments/assets/e22fcd4a-eaa1-448f-8c61-51164c6cbae7)

Operating System

Windows

Operating system details

11

Flet version

0.25

Regression

No, it isn't

Suggestions

No response

Logs

Logs ```console [Paste your logs here] ```

Additional details

No response

FeodorFitsner commented 3 days ago

What do you have in pyproject.toml and what is the file structure of your project?

OmarBelfeki commented 2 days ago

pyproject.toml

[project]
name = "weather-app"
version = "0.1.0"
description = ""
readme = "README.md"
requires-python = ">=3.8"
dependencies = [
  "flet"
]

[tool.flet]
# org name in reverse domain name notation, e.g. "com.mycompany".
# Combined with project.name to build bundle ID for iOS and Android apps
org = "com.mycompany"

# project display name that is used as an app title on Android and iOS home screens,
# shown in window titles and about app dialogs on desktop.
product = "Weather Forcast"

# company name to display in about app dialogs
company = "Flet"

# copyright text to display in about app dialogs
copyright = "Copyright (C) 2024 by Flet"

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

Structure

W:\dev-mobile\dev mobile (flet)\api-app\weather-app>flet build apk
[09:17:25] Created Flutter bootstrap project from gh:flet-dev/flet-build-template with ref 0.25.0 ✅
           Customized app icons and splash images ✅
[09:18:41] Generated app icons ✅
[09:18:51] Generated splash screens ✅
[09:21:48] Packaged Python app ✅
[09:30:39] Built .apk for Android ✅
           Copied build to build\apk directory ✅
           Successfully built your .apk for Android! 🥳 Find it in build\apk directory. 📁

Screenshot 2024-11-29 091419

Screenshot 2024-11-29 091455 Screenshot 2024-11-29 091512

ahhgo326 commented 2 days ago

I'm having the same problem. I created a basic project and built it right away, and it runs fine with flet run, but I get an error after building.

win11, 0.25.0

Commands used

mkdir flet-test
cd flet-test
flet create .
flet run
flet build windows -vv
cd flet build/windows
flet-test.exe

Error Description

Traceback (most recent call last):
  File "<string>", line 47, in <module>
  File "<frozen runpy>", line 222, in run_module
  File "<frozen runpy>", line 142, in _get_module_details
ImportError: No module named main

I filmed a video of the process.

https://github.com/user-attachments/assets/c6033991-4dbb-4967-9206-2f8833cd2640

The terminal log is here. ps-log.txt

Also, apps written with existing FLETs are experiencing the same error after updating from 0.24.1 to 0.25.0.

FeodorFitsner commented 2 days ago

Thanks for the additional details. I'm on it.

OmarBelfeki commented 2 days ago

++ when i run 'flet run main.py --android' is not working too on my phone (app flet)

FeodorFitsner commented 2 days ago

++ when i run 'flet run main.py --android' is not working too on my phone (app flet)

that's a different issue.

OmarBelfeki commented 2 days ago

i don't know if that issuse from me or flet