marimo+uv workflow

I just tried uv run --python 3.11 --with marimo --with numpy --with matplotlib marimo edit --sandbox hi.py the equivalent pattern for jupyterlab would be uv run --python 3.13 --with jupyterlab --with numpy --with matplotlib jupyter lab but now I'm wondering: When I start the marimo notebook notebook, why are the packages not installed? Currently I get the error: The following packages were not found: "matplotlib" , "numpy" (see screenshot)
No description
No description
39 Replies
Myles Scolnick
Myles Scolnick2mo ago
does it work if you use --with-requirements (and a req.txt) instead of --with? maybe a formatting issue with the --with command
Jan-Hendrik Müller
just tried
echo "pandas" > requirements.txt
uv run --with marimo --with-requirements "requirements.txt" marimo edit --sandbox hi.py
echo "pandas" > requirements.txt
uv run --with marimo --with-requirements "requirements.txt" marimo edit --sandbox hi.py
but that did not work as well. I also could not find the --with-requirements anywhere in the docs https://marimo.io/blog/sandboxed-notebooks , https://docs.astral.sh/uv/concepts/tools/#including-additional-dependencies
Jan-Hendrik Müller
Here's a workaround that does work:
uv add --script hi.py pandas matplotlib numpy
uv run --with marimo marimo edit --sandbox hi.py
uv add --script hi.py pandas matplotlib numpy
uv run --with marimo marimo edit --sandbox hi.py
Myles Scolnick
Myles Scolnick2mo ago
I wouldn’t chain “with” commands. That seems like an anti pattern and fragile And honestly, I wouldn’t use uv directly and instead just use “marimo edit —sandbox”. I think it complicates it —sandbox does for you what it looks like you are trying to achieve yourself, and hides away uv
Jan-Hendrik Müller
That makes sense! But I don't have a global installation of marimo. So I guess uvx marimo edit --sandbox hi.py would be the way to go then?
Myles Scolnick
Myles Scolnick2mo ago
That works - curious why not globally install it? It’ll save you 4 keystrokes each time
Jan-Hendrik Müller
how do I install marimo globally?
Myles Scolnick
Myles Scolnick2mo ago
This is the correct way in my opinion (I’m no uv expert) to use uv if you don’t want to install it globally Uv has a concept of tools - you can do “uv tool install marimo”. But that sits in its own venv - so I would only do that if you exclusively use sandbox
Jan-Hendrik Müller
I see! And would that be locked to a specific python version?
Myles Scolnick
Myles Scolnick2mo ago
lol it says the fix right there Read closely
Jan-Hendrik Müller
yep, it's uv tool update-shell
Jan-Hendrik Müller
just pasting the screenshot for documentation reasons, so that other members/LLMS can see the whole process. and e.g. when I now want to use python 3.11, would that be also possible?
Myles Scolnick
Myles Scolnick2mo ago
good idea
Akshay
Akshay2mo ago
That's a good question. I'm not sure if uv tool / uvx (uvx is a shorthand for uv tool) supports having multiple installations of the tool across multiple Python versions. Your feedback and experiments are helpful, we're still learning best practices of how to use uv
Jan-Hendrik Müller
small correction: accroding to their docs, uvx is a shorthand for uv tool run: https://docs.astral.sh/uv/concepts/tools/#the-uv-tool-interface
No description
Jan-Hendrik Müller
and next question: I just ran marimovia uvx marimo edit --sandbox marimo_uv.py and I get the message ther there's an update available to marimo 0.9.8. The terminal suggests me to usepip install marimo, but I guess it will be uv pip install --upgrade marimo ? Or should it be uv tool install marimo --upgrade?
No description
Jan-Hendrik Müller
I tried uv tool install marimo --upgrade now and that worked great 🍀
No description
Jan-Hendrik Müller
some inputs on this from their discord
No description
Myles Scolnick
Myles Scolnick2mo ago
Yea thats correct - we call uv run ourselves
Jan-Hendrik Müller
(second cross-post of the answer) I see! So in theory, the --python 3.11 flag could be called as well in that context?
Myles Scolnick
Myles Scolnick2mo ago
We could pass the python flag to uv in our cli args. Can you specify this with an environment variable?
Jan-Hendrik Müller
Can you specific this with an environment variable?
II dont understand, can you explain this a bit more?
Myles Scolnick
Myles Scolnick2mo ago
Sorry typo: specify Can you set the python version using an env variable
Jan-Hendrik Müller
Thanks for rephrasing, but I think I still don't understand the idea
Akshay
Akshay2mo ago
The suggestion is to set UV_PYTHON=python3.11 instead of using the CLI flag: https://docs.astral.sh/uv/configuration/environment/
Jan-Hendrik Müller
hey @Akshay , thanks for the suggestion! Indeed, prepending the environment variable to the command does work 🎉 in my zsh shell im Mac I can install UV_PYTHON=python3.11 uv tool install marimo and then run marimo edit hi.py and it will run python3.11. Similar I can run UV_PYTHON=python3.13 uv tool install marimo and then run marimo edit hi.py to use python3.13 (screenshot for reference)
No description
Akshay
Akshay2mo ago
Fantastic! For a one liner, you can even do the following:
UV_PYTHON=python3.13 uvx marimo edit hi.py
UV_PYTHON=python3.13 uvx marimo edit hi.py
Jan-Hendrik Müller
Awesome! But that I can also do with uvx --python 3.13 marimo edit hi.py , wich is maybe a bit cleaner. But is
uvx --python 3.13 marimo edit hi.py
and
UV_PYTHON=python3.13 uvx marimo edit hi.py
uvx --python 3.13 marimo edit hi.py
and
UV_PYTHON=python3.13 uvx marimo edit hi.py
100% identical?
Akshay
Akshay2mo ago
As far as I can tell from their docs, yea
Jan-Hendrik Müller
Awesome! Figuring out all this packaging stuff is like walking through fog, exploring and never knowing if you will reach the destiny. But on the path I think I figured out some best practices that I'll use now when working with marimo, that I'll share right here. 1. I'll have a global version of marimo installed via uv tool install marimo or with a specific python version using UV_PYTHON=python3.11 uv tool install marimo (this will overwrite the previous global installation) Furthermore, the global version of marimo can be updated via uv tool install marimo --upgrade. When I run a script with the global marimo version, I'll do that via marimo edit hi.py --sandbox When I run a script that already ran once with a --sandbox flag, I can simply omit this flag and run marimo edit hi.py The CLI tell me "This notebook has inlined package dependencies. Run in a sandboxed venv containing this notebook's dependencies? [Y/n]" and I'll press "Enter" to continue Now, when I don't want to use the global marimo, but a temporary marimo version instead, I'll run uvx marimo edit --sandbox hi.py this line is 100% identical to uv tool run marimo edit --sandbox hi.py because "uvx" is an alias to "uv tool run". I can also specify a python version here, like this uvx --python 3.13 marimo edit hi.py The thing about uvx marimo is the following: It's not installed, it's just cached. Runing uv cache clean will remove all artifacts from my system that were cached with uvx before. Another option is to work with a virtual environment using uv:
uv venv
uv pip install marimo
uv run marimo edit hi.py
uv venv
uv pip install marimo
uv run marimo edit hi.py
this venv can also be activated via source .venv/bin/activate and then marimo can be started via marimo edit hi.py . And always, if I'm not sure what marimo installation I'm currently using, I can run which marimo and it will show me the file path. Finally, I can also run marimo in a project with uv like this:
uv init (this will create a pyproject.toml file)
uv add marimo (this will add "marimo>=0.9.9" to dependencies in pyproject.toml)
uv run marimo edit hi.py
uv init (this will create a pyproject.toml file)
uv add marimo (this will add "marimo>=0.9.9" to dependencies in pyproject.toml)
uv run marimo edit hi.py
Akshay
Akshay2mo ago
Thank you for writing this up!
lucha6
lucha62mo ago
Why would you use global vs non global marimo? Can we use global marimo with a custom venv? Is uv add marimo functionally different to uv pip install marimo?
Jan-Hendrik Müller
Can we use global marimo with a custom venv?
I'm really interested in that question as well!