astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
25.71k stars 750 forks source link

When creating a venv pay attention to preferred Python version set via PY_PYTHON #6175

Open dalito opened 2 months ago

dalito commented 2 months ago

As of uv 0.2.37 (15dfb660a 2024-08-15) the environment variable PY_PYTHON is ignored. On my windows system I have 3.12 set as default version via the environment variable PY_PYTHON but have also 3.13.0rc1 installed. If I run uv venv a Python-3.13rc1 env is created.

C:\Users\david\MyProg\temp>echo %PY_PYTHON%
3.12

C:\Users\david\MyProg\temp>uv venv
Using Python 3.13.0rc1 interpreter at: C:\dev\Python313\python.exe
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate

C:\Users\david\MyProg\temp>py -m venv .venv_py
C:\Users\david\MyProg\temp>.venv_py\Scripts\activate
(.venv_py) C:\Users\david\MyProg\temp>python --version
Python 3.12.5

Feature request:

Read the preferred Python version for the virtual env from the env var PY_PYTHON (at least on Windows). This variable is used by the launcher and documented in the Python documentation under customizing-default-python-versions.

charliermarsh commented 2 months ago

Interesting, somehow I've never heard of PY_PYTHON. \cc @zanieb

dalito commented 2 months ago

I just discovered "pin" and thought that uv python pin 3.12 might configure uv to create a 3.12 venv by default afterwards but it doesn't. Then I found #4972 which seems to address this use case already.