1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] In a flet app I cannot access assets file, I receive a PathAccessException each time

Discussão em 'Python' iniciado por Stack, Outubro 1, 2024 às 00:02.

  1. Stack

    Stack Membro Participativo

    I'm using/learning flet v0.23.2 and every time I access (in read mode) a file on the /assets directory (the path is correct and the directory exists) I get this error:

    PathAccessException: Cannot open file, path = 'mypath/assets/icon.png' (OS Error: Operation not permitted, errno = 1)


    This is my code:

    import flet as ft

    def main(page: ft.Page):
    page.title = "Images Example"
    page.theme_mode = ft.ThemeMode.LIGHT
    page.padding = 50
    page.update()

    img = ft.Image(
    src=f"/assets/icon.png",
    width=100,
    height=100,
    fit=ft.ImageFit.CONTAIN,
    )
    images = ft.Row(expand=1, wrap=False, scroll="always")

    page.add(img, images)

    page.update()

    ft.app(main)


    I tried to run the app in these ways:

    flet run myapp.py
    flet run -a <path to assets> myapp.py


    and I tried with the app call is in this way:

    ...
    img = ft.Image(
    src=f"icon.png",
    width=100,
    height=100,
    fit=ft.ImageFit.CONTAIN,
    )
    ...
    flet.app(target=main, assets_dir="assets")


    I'm using a MAC OS and the assets directory and files are readable.

    Continue reading...

Compartilhe esta Página