Skip to content

uv sync --active sometimes deletes the active virtualenv #16631

@cdb39

Description

@cdb39

Summary

Running uv sync --active will delete and recreate the activated virtualenv when the following environment is used:

UV_PYTHON_INSTALL_DIR=.python-installs    # MUST be a relative path
UV_PYTHON_PREFERENCE=only-managed
UV_PYTHON_DOWNLOADS=automatic

This happens regardless of whether the active virtualenv already uses a uv managed python.

As the --active flag is designed for syncing to a virtualenv "outside of the project or script" I would never expect the sync command to delete it.

Example (from within a uv project directory)

export UV_PYTHON_INSTALL_DIR=.python-installs
export UV_PYTHON_PREFERENCE=only-managed
export UV_PYTHON_DOWNLOADS=automatic
uv venv foobar
source foobar/bin/activate
uv sync --active   # stdout tells you that uv "Removed virtual environment at: foobar"

Platform

Linux 6.8.0-85-generic x86_64 GNU/Linux

Version

uv 0.9.7

Python version

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions