Skip to content

Using uv with marimomarimoとuvの使用

marimo is an open-source Python notebook that blends interactive computing with the reproducibility and reusability of traditional software, letting you version with Git, run as scripts, and share as apps. Because marimo notebooks are stored as pure Python scripts, they are able to integrate tightly with uv.marimoは、インタラクティブな計算と従来のソフトウェアの再現性および再利用性を融合させたオープンソースのPythonノートブックで、Gitでバージョン管理を行い、スクリプトとして実行し、アプリとして共有することができます。marimoノートブックは純粋なPythonスクリプトとして保存されるため、uvと密接に統合することができます。

You can readily use marimo as a standalone tool, as self-contained scripts, in projects, and in non-project environments.marimoはスタンドアロンツールとして、自己完結型のスクリプトとして、プロジェクト内および非プロジェクト環境で簡単に使用できます。

Using marimo as a standalone toolmarimoをスタンドアロンツールとして使用する

For ad-hoc access to marimo notebooks, start a marimo server at any time in an isolated environment with:marimoノートブックにアドホックにアクセスするには、次のコマンドで隔離された環境でmarimoサーバーをいつでも開始します:

$ uvx marimo edit

Start a specific notebook with:特定のノートブックを開始するには:

$ uvx marimo edit my_notebook.py

Using marimo with inline script metadataインラインスクリプトメタデータを使用したmarimoの使用

Because marimo notebooks are stored as Python scripts, they can encapsulate their own dependencies using inline script metadata, via uv's support for scripts. For example, to add numpy as a dependency to your notebook, use this command:marimoノートブックはPythonスクリプトとして保存されるため、uvのスクリプトサポートを介してインラインスクリプトメタデータを使用して独自の依存関係をカプセル化できます。たとえば、numpyをノートブックの依存関係として追加するには、次のコマンドを使用します:

$ uv add --script my_notebook.py numpy

To interactively edit a notebook containing inline script metadata, use:インラインスクリプトメタデータを含むノートブックをインタラクティブに編集するには、次のコマンドを使用します:

$ uvx marimo edit --sandbox my_notebook.py

marimo will automatically use uv to start your notebook in an isolated virtual environment with your script's dependencies. Packages installed from the marimo UI will automatically be added to the notebook's script metadata.marimoは自動的にuvを使用して、スクリプトの依存関係を持つ隔離された仮想環境でノートブックを開始します。marimo UIからインストールされたパッケージは、自動的にノートブックのスクリプトメタデータに追加されます。

You can optionally run these notebooks as Python scripts, without opening an interactive session:インタラクティブセッションを開かずに、これらのノートブックをPythonスクリプトとして実行することもできます:

$ uv run my_notebook.py

Using marimo within a projectプロジェクト内でのmarimoの使用

If you're working within a project, you can start a marimo notebook with access to the project's virtual environment via the following command (assuming marimo is a project dependency):あなたがプロジェクト内で作業している場合、次のコマンドを使用してプロジェクトの仮想環境にアクセスできるmarimoノートブックを開始できます(marimoがプロジェクトの依存関係であると仮定します):

$ uv run marimo edit my_notebook.py

To make additional packages available to your notebook, either add them to your project with uv add, or use marimo's built-in package installation UI, which will invoke uv add on your behalf.ノートブックで追加のパッケージを利用可能にするには、uv addを使用してプロジェクトに追加するか、marimoの組み込みパッケージインストールUIを使用して、あなたの代わりにuv addを呼び出すことができます。

If marimo is not a project dependency, you can still run a notebook with the following command:marimoがプロジェクトの依存関係でない場合でも、次のコマンドを使用してノートブックを実行できます:

$ uv run --with marimo marimo edit my_notebook.py

This will let you import your project's modules while editing your notebook. However, packages installed via marimo's UI when running in this way will not be added to your project, and may disappear on subsequent marimo invocations.これにより、ノートブックを編集しながらプロジェクトのモジュールをインポートできます。ただし、この方法で実行中にmarimoのUIを介してインストールされたパッケージはプロジェクトに追加されず、次回のmarimoの呼び出し時に消える可能性があります。

Using marimo in a non-project environment非プロジェクト環境でのmarimoの使用

To run marimo in a virtual environment that isn't associated with a project, add marimo to the environment directly:プロジェクトに関連付けられていない仮想環境でmarimoを実行するには、marimoを環境に直接追加します:

$ uv venv
$ uv pip install numpy
$ uv pip install marimo
$ uv run marimo edit

From here, import numpy will work within the notebook, and marimo's UI installer will add packages to the environment with uv pip install on your behalf.ここから、import numpyはノートブック内で機能し、marimoのUIインストーラーはあなたの代わりにuv pip installを使用して環境にパッケージを追加します。

Running marimo notebooks as scriptsスクリプトとしてのmarimoノートブックの実行

Regardless of how your dependencies are managed (with inline script metadata, within a project, or with a non-project environment), you can run marimo notebooks as scripts with:依存関係がどのように管理されていても(インラインスクリプトメタデータ、プロジェクト内、または非プロジェクト環境)、次のコマンドでmarimoノートブックをスクリプトとして実行できます:

$ uv run my_notebook.py

This executes your notebook as a Python script, without opening an interactive session in your browser.これにより、ブラウザでインタラクティブセッションを開くことなく、ノートブックがPythonスクリプトとして実行されます。