-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Summary
I have discovered a problem with python versions installed by uv. The problem occurs if you use python (e.g. in version 3.12) to start an instance of another python version (e.g. 3.13), and it results in a runtime that has parts of both python versions loaded which will obviously not work.
This script should already demonstrate the problem:
uv python install 3.12
uv python install 3.13
echo "from os import environ;print(environ['PYTHONHOME']);import re" > test.py # or without "" for windows cmd
python3.12.exe -c "import subprocess; subprocess.run(['python3.13.exe', 'test.py'])"Instead of successfully returning, it will result in the following error:
C:\Users\CHG\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none
Traceback (most recent call last):
File "\\wsl.localhost\wsl-box\tmp\test.py", line 1, in <module>
from os import environ;print(environ['PYTHONHOME']);import re
File "C:\Users\CHG\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\re\__init__.py", line 125, in <module>
from . import _compiler, _parser
File "C:\Users\CHG\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\re\_compiler.py", line 18, in <module>
assert _sre.MAGIC == MAGIC, "SRE module mismatch"
AssertionError: SRE module mismatch
The problem does not only affect of python directly starting another python instance, but also starting instances of tools that were installed with uv tool, e.g. uv tool install conan. This makes the problem much more likely because it is not so unusual to use python to start other tools, that may require a different python version.
My analysis has brought up that it is related to the handling of the PYTHONHOME environment variable. It seems like tools and python versions installed by uv does not override externally set PYTHONHOME values leading to the described problems.
Platform
Windows 11 x86_64
Version
uv 0.9.28 (0e1351e 2026-01-29)
Python version
Python 3.12, Python 3.13