Skip to content

session.install fails with uv backend if UV_PYTHON is set #948

@MikkelSchubert

Description

@MikkelSchubert

Current Behavior

Session.install fails when using uv as the backend, and the UV_PYTHON environment variable is set to a different version of Python than is being used by the current session

Expected Behavior

nox could perhaps filter UV_PYTHON and/or show a warning if it is set

Steps To Reproduce

For the following nox file

import nox

nox.options.default_venv_backend = "uv"

@nox.session(python=["3.11"])
def tests(session):
    session.install("pytest")

Without UV_PYTHON

$ rm -rf .nox __pycache__
$ unset UV_PYTHON
$ nox
nox > Running session tests-3.11
nox > Creating virtual environment (uv) using python3.11 in .nox/tests-3-11
nox > uv pip install pytest
nox > Session tests-3.11 was successful.

With UV_PYTHON

$ rm -rf .nox __pycache__
$ export UV_PYTHON=3.12
$ nox
nox > Running session tests-3.11
nox > Creating virtual environment (uv) using python3.11 in .nox/tests-3-11
nox > uv pip install pytest
nox > Command uv pip install pytest failed with exit code 2:
error: No virtual environment found for Python 3.12; run `uv venv` to create an environment, or pass `--system` to install into a non-virtual environment
nox > Session tests-3.11 failed.

Environment

- OS: Linux Mint 22
- Python: 3.11.11 (managed by uv) and 3.12.3 (system)
- Nox: 2025.2.9
- Uv: 0.6.11

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions