mise/Python/How To/Use mise to set up a virtualenv with uv
Properties
- tags
- Diataxis/How To
How to configure a project mise/Config/mise.toml with the ability to manage a python virtualenv with uv
Goal
Preconditions
- You have
mise≥ 2025.5.6 installed globally. - A Git repository with a pyproject.toml defining your Python project's metadata and dependencies.
- You want all Mise configuration in
mise.toml, not inpyproject.toml.
- You have
Procedure
1. Create and commit
mise.toml- At your project root, add a file named
mise.toml:toml[env] # Use the project name derived from the current directory PROJECT_NAME = "{{ config_root | basename }}" # Automatic virtualenv activation _.python.venv = { path = ".venv", create = true } [tools] # Python version (via pyenv, as a fallback to .python-version) python = "{{ get_env(name='PYTHON_VERSION', default='3.13') }}" uv = "latest" ruff = "latest" [tasks.install-deps] description = "Install all basic dependencies" alias = "id" run = "uv sync --all-extras" [tasks.install-deps-dev] description = "Install only dev dependencies" alias = "idd" run = "uv sync --extras dev" [tasks.install-deps-all] description = "Install all dependencies (including dev dependencies)" alias = "ida" run = "uv sync --all-extras" [tasks.add-deps] description = "Add new dependencies using uv" alias = "ad" run = "uv pip install $@" [tasks.test] description = "Run tests" run = "pytest tests/" [tasks.lint] description = "Lint the code" run = "ruff check ." [tasks.format] description = "Format the code" run = "ruff format ." [tasks.info] description = "Print project information" run = ''' echo "Project: $PROJECT_NAME" echo "Virtual Environment: $VIRTUAL_ENV" ''' - Use
mise.local.tomlfor machine-specific overrides and add it to.gitignore.
- At your project root, add a file named
2. Install and pin tools
3. Define tasks for Python dependency management
- The
mise.tomlabove defines several useful tasks:mise run install-deps(ormise run id): Install all basic dependenciesmise run install-deps-dev(ormise run idd): Install only dev dependenciesmise run install-deps-all(ormise run ida): Install all dependenciesmise run add-deps <package>(ormise run ad <package>): Add new dependenciesmise run test: Run testsmise run lint: Lint the codemise run format: Format the codemise run info: Show project information
- The
4. Keep Python dependencies in
pyproject.toml5. Ignore artifacts
6. First-time setup for contributors
git clone <repo> && cd <repo>Ensure
mise activate zsh(or your shell) is in your shell RC.Run
mise installto install pinned tools.Run
mise run install-depsto create and populate the venv with basic dependencies.(Optional) Run
mise run install-deps-devif you need development dependencies.
7. Register the venv with VS Code
- Open VS Code Command Palette (
⇧⌘P/Ctrl+Shift+P) and run Python: Select Interpreter. - Choose the interpreter at
./.venv/bin/python. - (Optional) Add a workspace setting in
.vscode/settings.json:json{ "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python" } - VS Code will now use the project's venv for linting, debugging, and IntelliSense.
- Open VS Code Command Palette (
Troubleshooting
- Mise didn't pick up
mise.tomlRun
mise config lsto confirm which config files are active. - Python version mismatch
Ensure you ran
mise use --project python@3.13; check withpython --version. - VS Code can't find the interpreter
Make sure you pointed to the correct
.venv/bin/pythonpath and reload the window.
- Mise didn't pick up
References
- Walkthrough: Configure a project-local mise.toml
- Python tool guide: Automatic virtualenv activation
- Mise + Python Cookbook: Using mise with uv