-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Summary
Short summary
Ephemeral environments created via --with do not contain the "scripts" entry points (Windows: scripts/<script>.exe, Linux: bin/<script>) of their base venv. Thus, if one launches such an entry point from an ephemeral venv, one ends up running the interpreter from the base venv which lacks the packages installed by --with.
I already asked about this in discord and @zanieb replied it might be worth opening an issue because it might be a bug.
If it is not a bug, then at least it might be worth a warning in the documentation of the --with parameter.
Minimal example
Windows cmd commands
uv init uvEphemeralScriptsExample
cd uvEphemeralScriptsExample
uv add pytest
# (Now we have an entry point we want to use: .venv/scripts/pytest.exe)
mkdir tests
# Add a test case that depends on another package, e.g. "pyyaml". We will install that package via --with
(echo def test_pyyaml^(^):& echo import yaml)> tests\test_pyyaml.py
uv run --with pyyaml python -c "import subprocess;subprocess.run(['pytest'], text=True)"
Work arounds / why is this bad?
In my particular use case the script I needed was pytest and a work around was to call [sys.executable, "-m", "pytest"].
But the pytest docs have an explicit warning that this triggers slightly different behavior: https://docs.pytest.org/en/7.1.x/explanation/pythonpath.html#invoking-pytest-versus-python-m-pytest
Also, other python packages might define more complicated entry points and trying to circumvent the entry-points to directly call the underlying API seems like bad practice.
Platform
Windows
Version
uv 0.7.2 (481d05d 2025-04-30)
Python version
tested on 3.9 and 3.13