Flexible Python Version Management with uv and tox

Flexible Python Version Management with uv and tox

February 12, 2025

When working with Python projects that use tox for testing, you may encounter version mismatch errors like:

lint-format: skipped because could not find python interpreter with spec(s): python3.8

This happens when tox expects a specific Python version that isn’t available in your environment. Traditionally, this would require:

  1. Installing the required Python version
  2. Creating a new virtualenv
  3. Reinstalling dependencies
  4. Running tox again

However, uv provides a more elegant solution through its tool isolation feature. By using uvx with the --python flag, you can run tox with any Python version on demand:

$ uvx --python 3.8 tox -e lint
ℹ️

uvx creates an isolated environment with the specified Python version just for this command execution, leaving your project’s environment untouched.

uv also _automatically installs_ Python 3.8 if you don’t have it available on your system.

This approach offers several advantages:

  • No need to manage multiple virtualenvs
  • Works with any Python version uv can access
  • Maintains isolation between environments
  • Zero configuration required
Last updated on

Please submit corrections and feedback...