Skip to content

uv does not respect the UV_PROJECT_ENVIRONMENT environment variable anymore #19792

Description

@angelo-peronio

Summary

While waiting for #18214 , I have been using this trick to tell uv sync where to put the Python environment

uv run --env-file=.env -- uv sync

where the .env file contains a line analoguous to UV_PROJECT_ENVIRONMENT=C:/venvs/uv-mre.

As of lately, this does not work anymore: the Python environment is created in .venv nonetheless. Possibly the same as #19540 .

Minimal reproducible example

Create a minimal pyproject.toml

[project]
name = "uv-mre"
version = "0.1.0"

then run the following with PowerShell

PS>"UV_PROJECT_ENVIRONMENT=C:/venvs/uv-mre" > .env
PS>uv run --verbose --env-file=.env -- python -c "import os; print(os.environ['UV_PROJECT_ENVIRONMENT'])"

I obtained

DEBUG Found workspace root: `C:\cache\uv-mre`
DEBUG Adding root workspace member: `C:\cache\uv-mre`
DEBUG Skipping `pyproject.toml` in `C:\cache\uv-mre` (no `[tool]` section)
DEBUG Searching for user configuration in: `C:\Users\peronian\AppData\Roaming\uv\uv.toml`
DEBUG uv 0.11.20 (9252ba6b5 2026-06-10 x86_64-pc-windows-msvc)
DEBUG Read environment file at: `.env`
DEBUG Found project root: `C:\cache\uv-mre`
DEBUG No workspace root found, using project root
DEBUG Discovered project `uv-mre` at: C:\cache\uv-mre
DEBUG No Python version file found in workspace: C:\cache\uv-mre
DEBUG Checking for Python environment at: `.venv`
DEBUG Searching for default Python interpreter in managed installations, search path, or registry
DEBUG Searching for managed installations at `C:\Users\peronian\AppData\Roaming\uv\python`
DEBUG Found managed installation `cpython-3.14.5-windows-x86_64-none`
DEBUG Found `cpython-3.14.5-windows-x86_64-none` at `C:\Users\peronian\AppData\Roaming\uv\python\cpython-3.14-windows-x86_64-none\python.exe` (managed installations)
Using CPython 3.14.5
Creating virtual environment at: .venv
DEBUG Using base executable for virtual environment: C:\Users\peronian\AppData\Roaming\uv\python\cpython-3.14-windows-x86_64-none\python.exe
DEBUG Using junction C:\Users\peronian\AppData\Roaming\uv\python\cpython-3.14-windows-x86_64-none instead of base Python path: C:\Users\peronian\AppData\Roaming\uv\python\cpython-3.14-windows-x86_64-none\python.exe
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.14`.
DEBUG Using request connect timeout of 10s and read timeout of 30s
DEBUG Found static `requires-dist` for: C:\cache\uv-mre\
DEBUG Existing `uv.lock` satisfies workspace requirements
Resolved 1 package in 2ms
DEBUG Using request connect timeout of 10s and read timeout of 30s
Checked in 0.01ms
DEBUG Using Python 3.14.5 interpreter at: C:\cache\uv-mre\.venv\Scripts\python.exe
DEBUG Running `python -c import os; print(os.environ['UV_PROJECT_ENVIRONMENT'])`
C:/venvs/uv-mre
DEBUG Command exited with code: 0

In short

  • uv run finds the .env file and sets the UV_PROJECT_ENVIRONMENT environment variable correctly.
  • The virtual environment is created nonetheless in .venv, and not in the folder specified by UV_PROJECT_ENVIRONMENT.

Platform

Wndows 11 x86_64

Version

uv 0.11.20

Python version

Python 3.14.5

Activity

  1. zanieb commented on Jun 11, 2026

    @zanieb
    Member

    uv does not read its own settings from .env files — there were some places where we were by accident, which I believe was recently fixed as a bug.

  2. added
    questionAsking for clarification or support
    and removed
    bugSomething isn't working
    on Jun 11, 2026
  3. angelo-peronio commented on Jun 12, 2026

    @angelo-peronio
    Author

    I see, this happened in #19567 and #19343 . I guess I fell victim of Hirum's law.

    Maybe mention the fact that uv does not read its own settings from .env files in the docs, e.g. here?

    Feel free to close, and thank you!

  4. charliermarsh commented on Jun 13, 2026

    @charliermarsh
    Member

    Sorry about that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for clarification or support

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions