Skip to content

uv sync with upgraded system Python version fails to update activate_this.py #12461

@andersk

Description

@andersk

Summary

An uv virtual environment using the system Python version embeds a reference to the Python minor version number in activate_this.py.

$ docker run --rm -it ubuntu:22.04
# apt update
# apt install -y curl python3 python3.11
# curl -LsSf https://astral.sh/uv/install.sh | sh
# source $HOME/.local/bin/env
# uv init --no-pin-python app
# cd app
# uv add numpy
# grep site-packages .venv/bin/activate_this.py 
for lib in "../lib/python3.10/site-packages".split(os.pathsep):

If we then upgrade the system’s Python version (simulated here by changing the /usr/bin/python3 symlink, but an OS upgrade has the same effect), uv sync correctly installs wheels for the new Python version, but incorrectly leaves activate_this.py unchanged.

# ln -nsf python3.11 /usr/bin/python3
# uv sync
# uv run python -c 'import numpy; print(numpy)'
<module 'numpy' from '/app/.venv/lib/python3.11/site-packages/numpy/__init__.py'>
# grep site-packages .venv/bin/activate_this.py
for lib in "../lib/python3.10/site-packages".split(os.pathsep):

There are ways to force it to fix activate_this.py, e.g. uv sync -p python3.10; uv sync -p python3.11 (both commands are necessary). However, a simple uv sync ought to automatically update activate_this.py without further workarounds.

Platform

Ubuntu 22.04 amd64

Version

uv 0.6.9

Python version

Python 3.10.12

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