UnsupportedRelativePath: Paths that aren't prefixed with a leading / are not supported

Hello:
I am working on Windows and I would like to read an image with ‘app.get_relative_path’.
But I am not able to resolve the issue mentioned in the header.
I do not have permissions to write on the top level of the directory.

Is there a workaround?
Many thanks in advance,
Markus

Hi @metma,

Relative paths should work fine as-is. Below is an example of reading and displaying a file in Dash.

SEM.jpg

from dash import Dash, html
import base64


def get_img_str(img_path):
    with open(img_path, 'rb') as img:
        img_b64 = base64.b64encode(img.read()).decode('UTF-8')

    if img_path[-3:] == 'png':
        img_str = 'data:image/png;base64,' + img_b64
    else:
        img_str = 'data:image/jpg;base64,' + img_b64
    return img_str


app = Dash(__name__)
app.layout = html.Div([
    html.Img(src=get_img_str('SEM.jpg'))
])

if __name__ == '__main__':
    app.run(debug=True, port=8050)

Thank you very much!