Skip to content

ImportError: No module named main when running packaged Flet app on Windows 11, works on Windows 10 #5780

@jessic-cmd

Description

@jessic-cmd

Duplicate Check

Describe the bug

When running a Flet application packaged on Windows 11, I encounter an ImportError: No module named main. The same packaged application runs without issues on Windows 10. Crucially, the exact same packaged application also runs successfully on my colleague's Windows 11 machine, indicating the issue might be specific to my personal Windows 11 setup.

The application fails to launch and outputs the following error in the console:

Traceback (most recent call last):
  File "<string>", line 95, 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 searched Flet's GitHub issues and found a similar problem in #5375. That issue suggested a potential problem with the project.toml file. I tried replacing my project.toml file with the original one automatically generated by Flet, but the issue persists, and the error message remains unchanged.

Code sample

Code
import flet as ft

def main(page: ft.Page):

    def pick_files_result(e: ft.FilePickerResultEvent):
        selected_files.value = (
            ", ".join(map(lambda f: f.path, e.files)) if e.files else "Cancelled!"
        )
        selected_files.update()

    def get_directory_result(e: ft.FilePickerResultEvent):
        selected_directory.value = e.path if e.path else "Cancelled!"
        selected_directory.update()

    # Create hidden file pickers
    pick_files_dialog = ft.FilePicker(on_result=pick_files_result)
    get_directory_dialog = ft.FilePicker(on_result=get_directory_result)

    # Add dialogs to page overlay
    page.overlay.extend([pick_files_dialog, get_directory_dialog])

    selected_files = ft.Text()
    selected_directory = ft.Text()

    # Add UI components
    page.add(
        ft.Row(
            [
                ft.ElevatedButton(
                    "Select Files",
                    icon=ft.Icons.UPLOAD_FILE,
                    on_click=lambda _: pick_files_dialog.pick_files(
                        allow_multiple=True
                    ),
                ),
                selected_files,
            ]
        ),
        ft.Row(
            [
                ft.ElevatedButton(
                    "Select Folder",
                    icon=ft.Icons.FOLDER_OPEN,
                    on_click=lambda _: get_directory_dialog.get_directory_path(),
                ),
                selected_directory,
            ]
        ),
    )

if __name__ == '__main__':
    ft.app(target=main)
[project]
name = "flettest"
version = "1.2"
description = ""
requires-python = ">=3.9"
authors = [
    { name = "developer", email = "test@outlook.com" }
]
dependencies = [
    "flet==0.28.3",
]

[tool.flet]

copyright = "Copyright (C) 2025 by flet"

[tool.flet.compile]
app = true
packages = true
cleanup = true

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

[tool.flet.app.boot_screen]
show = true
message = "starting..."

[tool.flet.app.startup_screen]
show = true
message = "welcome..."

To reproduce

The exact same packaged executable runs successfully on a Windows 10 machine and on a colleague's Windows 11 machine.

Expected behavior

No response

Screenshots / Videos

Captures

[Upload media here]

Operating System

Windows

Operating system details

11

Flet version

0.28.3

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions