Importing external files in the same directory
I have a question that might seem silly, but I couldn't find an answer through searching. I am currently running Marimo as a service using sysvinit on Ubuntu, with the root directory in the services file set to my home directory.
When I create a Marimo project directory under my home directory, let's call the directory "experiment1", and try , from a marimo notebook in that same directory to import a utils.py file which is also in the experiment1 directory, I have to use the following syntax:
I have around 5-6 different notebooks, each importing from 2-3 external files using this method. As I duplicate the directories to run different experiments, it's becoming tedious to manually change the references in each notebook.
Is there a way to import external files in Marimo notebooks
without having to specify the full path every time, considering that the notebook and the external files are located in the same directory? Any hints or suggestions would be greatly appreciated!
11 Replies
Hey! Thanks for the question. Bear with me because I haven't run marimo (or jupyterhub) as a service before, so I have some basic questions/remarks in response.
1. When you say you're running marimo as a service: are you running
marimo edit
, which launches the homepage? Is that how you're opening notebooks?
2. When we start a notebook, we append the notebook directory to the Python path. So I'm surprised that marimo can't find modules colocated in the notebook directory.
3. Can you reproduce this issue without starting marimo as a service? Or is this issue specific to starting it as a service?1. yes
I am basically setting up marimo to start as a service. This is the relevant section from the init configuration file for marimo:
It starts marimo as :
i am using sysvinit .. so init.d is a directory for initialization scripts, used by SysVinit, an old init and service manager. I can't run systemctl/systemd manager cause the machine is containerized.
That above is a snapshot of my /etc/init.d/marimo
If you start
marimo edit
from your home directory, but not as a service, do you run into the same problem? I don't, so I want to see if this is somehow specific to running it as a serviceI will check and let you know by tomorrow. pulling an all nighter to finish a project 😄
Sounds good -- good luck!
what's the equivalent of %%time in marimo? 😄
still getting used to it
shrugging at the keyword based search on the website
We don't have Jupyter magics, so it would just be the Python equivalent. You could use the
timeit
module: https://docs.python.org/3/library/timeit.htmlPython documentation
timeit — Measure execution time of small code snippets
Source code: Lib/timeit.py This module provides a simple way to time small bits of Python code. It has both a Command-Line Interface as well as a callable one. It avoids a number of common traps fo...
We have a RAG bot for our docs (thanks @vrtnis!) in #ask-docs-ai
sounds good!
oh nice . thank you. still new to marimo. I am a 1 week old.
Of course! No problem. Thanks for using marimo, and thanks for the feedback/questions!
i hope to migrate all my work to it. I had a major problem with notebooks on jupyterhub dying off when we get disconnected , especially where some workloads can literaly take hours.
talk soon. thank you
@Akshay i actually solved this.
it was a question of specifying PYTHONPATH="/home/discy/discy/utils:${PYTHONPATH}" in the environment statement under the [program:marimo] section of supervisor
/home/discy/discy/utils basically contains the .py files i want to import
now i can do:
without having to:
i am basically running marimo as a server now