Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: expand user for mo.image() (#1968)

Akshay Agrawalbc2ae8a74122
diff --git a/marimo/_plugins/stateless/image.py b/marimo/_plugins/stateless/image.py
index 8d0d3d089b..5d057e1859 100644
--- a/marimo/_plugins/stateless/image.py
+++ b/marimo/_plugins/stateless/image.py
@@ -139,10 +139,12 @@ def image(
resolved_src = mo_data.image(src.read()).url
elif isinstance(src, bytes):
resolved_src = mo_data.image(src).url
- elif isinstance(src, str) and os.path.isfile(src):
- with open(src, "rb") as f:
+ elif isinstance(src, str) and os.path.isfile(
+ expanded_path := os.path.expanduser(src)
+ ):
+ with open(expanded_path, "rb") as f:
resolved_src = mo_data.image(
- f.read(), ext=os.path.splitext(src)[1]
+ f.read(), ext=os.path.splitext(expanded_path)[1]
).url
else:
resolved_src = io_to_data_url(src, fallback_mime_type="image/png")