Get help from the marimo community

Updated last week

Unable to find hydra config

At a glance

A community member encountered issues loading Hydra config files after converting a Jupyter notebook to Marimo, with the system looking for config files in a temporary directory instead of the project root. The solution is to use absolute paths with mo.notebook_dir() to properly reference config files.

The discussion expanded to include handling relative paths in Marimo, where it was clarified that the working directory is where Marimo is started. For both config files and local module imports, community members recommend using mo.notebook_dir() to construct paths relative to the notebook file's location.

A reference to a Discord conversation was mentioned where additional details about the Hydra fix were discussed.

Useful resources
Hi there, i'm a current Jupyter user and am trying out Marimo for the first time.

I have used the converter command to convert my Jupyter notebook to Marimo.
Currently, i'm facing an issue where i cannot load my hydra config in the Marimo notebook.

I have ran marimo edit --headless --host 0.0.0.0 --port 8883 in my root dir (/~/project), which is where marimo_notebook.py resides.

project
|- config
|- hydra
|- config.yaml
|- marimo_notebook.py

However, when i run the following to initialize my hydra config:
Plain Text
with hydra.initialize(config_path='./config/hydra'):
    config_1 = hydra.compose(config_name='config')

I get the error below:
Plain Text
Traceback:
...
    self._missing_config_error(
  File "/opt/conda/lib/python3.10/site-packages/hydra/_internal/config_loader_impl.py", line 102, in _missing_config_error
    raise MissingConfigException(
hydra.errors.MissingConfigException: Primary config directory not found.
Check that the config directory '/tmp/marimo_5081/config/hydra' exists and readable


Why is the root dir: /tmp/marimo_5081/ instead of project?
Marked as solution
Pass an absolute path to the config param? mo.notebook_dir() + “config/hydra” for example
View full solution
u
A
6 comments
Pass an absolute path to the config param? mo.notebook_dir() + “config/hydra” for example
Thanks! Passing the absolute path did work for me.
However im just curious, how does marimo treats relative paths?
I was also trying to import local modules via the following way below and it did not register:

  1. Started Marimo in directory (i.e. /~/project)
  2. Created my notebook in a subfolder of directory (i.e. /~/project/notebook)
  3. Has local modules in other subfolders of directory (i.e. /~/project/source_codes/data_generator)
  4. Tries to import the local modules into Marimo via this way in the cell (currently this is how i do it in jupyter):
Plain Text
import sys 
sys.path.append("../")
import source_codes.data_generator import generate_data_func


Got error: ModuleNotFoundError
The working directory is the directory where marimo is started — this is what python does. We recommend using mo.notebook_dir() to construct paths relative to where the notebook file is
Thanks! Will try it out!
Add a reply
Sign up and join the conversation on Discord