Skip to content

Commit

Permalink
update cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
hverlin committed Jan 29, 2025
1 parent 3c5cdcc commit 46fa1c5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/lang/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ The venv will need to be created manually with `python -m venv /path/to/venv` un

## mise & uv

If you have installed `uv` (for example, with `mise use -g uv@latest`, `mise` will use it to create virtual environments. Otherwise, it will use the built-in `python -m venv` command.
If you have installed `uv` (for example, with `mise use -g uv@latest`), `mise` will use it to create virtual environments. Otherwise, it will use the built-in `python -m venv` command.

Note that `uv` does not include `pip` by default (as `uv` provides `uv pip` instead). If you need the `pip` package, add the `uv_create_args = ['--seed']` option.

See the [mise + uv Cookbook](/mise-cookbook/python.html#mise-+-uv) for more examples.

## Default Python packages

mise can automatically install a default set of Python packages with pip right after installing a
Expand Down
55 changes: 54 additions & 1 deletion docs/mise-cookbook/python.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mise + Python Cookbook

Here are some tips on managing Python projects with mise.
Here are some tips on managing [Python](/lang/python.html) projects with mise.

## A Python Project with virtualenv

Expand Down Expand Up @@ -44,3 +44,56 @@ echo "Project: $PROJECT_NAME"
echo "Virtual Environment: $VIRTUAL_ENV"
'''
```

## mise + uv

If you are using a `uv` project initialized with `uv init .`, here is how you can use it with mise.

Here is how the `uv` project will look like:

```shell [uv-project]
.
├── .gitignore
├── .python-version
├── hello.py
├── pyproject.toml
└── README.md

cat .python-version
# 3.12
```

If you run `uv run hello.py` in the `uv` project, `uv` will automatically create a virtual environment for you using the python version specified in the `.python-version` file. This will also create a `uv.lock` file.

`mise` will detect the python version in `.python-version`, however, it won't use the virtual env created by `uv` by default. So, using `which python` will show a global python installation from `mise`.

```shell
mise i
which python
# ~/.local/share/mise/installs/python/3.12.4/bin/python
```

If you want `mise` to use the virtual environment created by `uv`, you can set the [`python.uv_venv_auto`](/lang/python.html#python.uv_venv_auto) setting to `true` in your `mise.toml` file.

```toml [mise.toml]
[settings]
python.uv_venv_auto = true
```

Using `which python` will now show the python version from the virtual environment created by `uv`.

```shell
which python
# ./uv-project/.venv/bin/python
```

Another option is to use `_.python.venv` in your `mise.toml` file to specify the path to the virtual environment created by `uv`.

```toml [mise.toml]
[env]
_.python.venv = { path = ".venv" }
```

### Syncing python versions installed by mise and uv

You can use [uv sync python --uv](/cli/sync/python.html#uv) to sync the python version installed by `mise` with the python version specified in the `.python-version` file in the `uv` project.

0 comments on commit 46fa1c5

Please sign in to comment.