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.
1
...
img = ft.Image(
src=f"/icon.png",
width=100,
height=100,
fit=ft.ImageFit.CONTAIN,
)
...
flet.app(target=main, assets_dir="assets")
I think if you just add the slash before your relative file paths it should be fixed.