Get help from the marimo community

Updated 3 months ago

current working directory when python file in subfolder

At a glance

The community member is trying to run a Python script in the subfolder directory using the marimo tool, but the current working directory (cwd) is set to the parent directory /Users/jan-hendrik/projects/okapi. The community member wants to know if there is a way to start marimo so that the Python cwd is directly in the subfolder.

In the comments, community members suggest two workarounds:

  1. Manually change the directory to the subfolder before running the marimo command: cd subfolder; uv run marimo edit hello.py
  2. Use the mo.notebook_dir() function from the marimo library to get the directory of the current notebook, which ensures compatibility regardless of the cwd.

There is no explicitly marked answer in the comments.

When I run
uv run marimo edit subfolder/hello.py
and then type

Plain Text
import os
print(os.getcwd())

I'll get
Plain Text
/Users/jan-hendrik/projects/okapi

without the subfoloder.
Therefore my question: Is there a way to start marimo, so that the python cwd is directly in the subfolder?
Attachment
image.png
J
M
3 comments
my current workaround:
Plain Text
cd subfolder
uv run marimo edit hello.py
you would need to cd into the directory. I always use mo.notebook_dir() in all my notebooks so they are compatible wherever they are run (and when run as a script)
Plain Text
import marimo as mo
pl.read_csv(mo.notebook_dir()  / "data" / "my.csv")
Add a reply
Sign up and join the conversation on Discord