uv icon indicating copy to clipboard operation
uv copied to clipboard

`--system` didn't fallback to running environment when `uv` installed as python package.

Open T-256 opened this issue 1 year ago • 7 comments

  1. create a venv and install uv in it.
  2. make sure you don't have python on the PATH.
  3. cd parent-dir to prevent .venv detection
C:\Users\User\Desktop> uvtest\.venv\Scripts\python -m uv pip list
Package Version
------- -------
uv      0.1.12

C:\Users\User\Desktop> uvtest\.venv\Scripts\python -m uv pip list --system
error: Could not find `python.exe` through `py --list-paths` or in 'PATH'. Is Python installed?

Expected: Both of them should select uvtest\.venv\Scripts\python.

T-256 avatar Feb 28 '24 22:02 T-256

What's the use-case / motivation for invoking uv through python -m uv? (As an FYI, that will add a bunch of overhead to each invocation.)

charliermarsh avatar Feb 28 '24 22:02 charliermarsh

(This looks straightforward to fix though.)

charliermarsh avatar Feb 28 '24 22:02 charliermarsh

$ uv pip list --help
      [...]
      --system
          List packages for the system Python.

          By default, `uv` lists packages in the currently activated virtual environment, or a virtual environment (`.venv`) located in the current working directory or any parent directory, falling back to the system Python if no virtual environment is found. The `--system` option instructs `uv` to use the first Python found in the system `PATH`.

I don't understand why this is a bug. From "use the first Python found in the system PATH" I would expect the observed behavior: Python is not in the PATH, so uv throws an error.

NMertsch avatar Feb 28 '24 22:02 NMertsch

Yeah, I guess this is debatable.

Why pass system to this invocation?

charliermarsh avatar Feb 28 '24 22:02 charliermarsh

What's the use-case / motivation for invoking uv through python -m uv? (As an FYI, that will add a bunch of overhead to each invocation.)

Actually, this doesn't have any usecase imo. Since first command successfully found and fallback to caller, I expected --system should did it too.

I don't understand why this is a bug. From "use the first Python found in the system PATH" I would expect the observed behavior: Python is not in the PATH, so uv throws an error.

Since --system is shorthand of --python $(which python3), I think in perspective of modules run as scripts (-m), the python/python3 executables are already on PATH environment. An example from rye app that returns PATH variable:

> rye run hello
C:\Users\User\Desktop\New folder (2)\ttt\.venv\Scripts;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\downlevel;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;

T-256 avatar Feb 28 '24 22:02 T-256

What about we set UV_DEFAULT_PYTHON in the launcher and use that as precedence over python for the default python in uv? Many people are very used the python -m not only working, but being necessary to do the right thing, so i'd like to support that.

konstin avatar Mar 07 '24 15:03 konstin

I suggest a similar thing in https://github.com/astral-sh/uv/issues/2222#issuecomment-1979838755

I'm not opposed to it.

zanieb avatar Mar 07 '24 17:03 zanieb