Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print installation path when running uv pip install #2155

Closed
danielhollas opened this issue Mar 4, 2024 · 13 comments · Fixed by #7850
Closed

Print installation path when running uv pip install #2155

danielhollas opened this issue Mar 4, 2024 · 13 comments · Fixed by #7850
Labels
enhancement New feature or request good first issue Good for newcomers tracing Verbose output and debugging

Comments

@danielhollas
Copy link

Hey 👋

Small feature request: It would be great if uv printed the path where it is installing the packages when running uv pip install. I am currently debugging a weird issue in GHA while using uv pip install --system and it is not clear how to check where uv ends up installing stuff.

@charliermarsh
Copy link
Member

Have you tried running with --verbose?

@charliermarsh charliermarsh added the question Asking for clarification or support label Mar 4, 2024
@danielhollas
Copy link
Author

Yeah, indeed running with verbose prints this:

 uv_interpreter::python_query::find_default_python 
      0.004003s   0ms DEBUG uv_interpreter::python_query Starting interpreter discovery for default Python
      0.004109s   0ms DEBUG uv_interpreter::interpreter Probing interpreter info for: /opt/hostedtoolcache/Python/3.10.13/x64/bin/python3
      0.039094s  35ms DEBUG uv_interpreter::interpreter Found Python 3.10.13 for: /opt/hostedtoolcache/Python/3.10.13/x64/bin/python3
    0.039395s DEBUG uv::commands::pip_install Using Python 3.10.13 environment at /opt/hostedtoolcache/Python/3.10.13/x64/bin/python3

To me, this is not very easy to parse, and even find among the rest of the huge debug output. At least for the --system flag seems like a good info to print by default, especially given the number of issues / corner cases that have been reported (and fixed!) for this particular option. But of course opinions might vary. :-)

@woutervh
Copy link

woutervh commented Mar 5, 2024

it is not clear how to check where uv ends up installing stuff.

I've already been bitten multiple times by this, installing stuff in the wrong venv.
Because I have 100 venvs on my system,
and I really dislike activating a venv (because it's an anti-patteren creating state in that specific shell.)

with actual pip, it's not really an issue, because you are always using the pip from inside the virtualenv

> uv pip install pytest
Resolved 4 packages in 286ms
Downloaded 1 package in 64ms
Installed 4 packages in 21ms
 + iniconfig==2.0.0
 + pytest==8.0.2
  ...

A much more userfriendly output would be to include the path somewhere

> uv pip install pytest
Resolved 4 packages.                                <- I don't care about how many millisecs it takes,  it's visual pollution
Downloaded 1 package.                           <- which one?  what if I don't expect to download anything new?
Installed 4 packages in /tmp/foo/.venv/   <- include path
  ...
  + iniconfig==2.0.0
 + pytest==8.0.2  (dowloaded)

@danielhollas
Copy link
Author

So, I love the new more concise verbose output (-v), however, I will still lobby for uv to print the install location by default. 😊

As previous commenter pointed out, it's too easy to make a mistake and not notice it (e.g. forgetting to deactivate the environment, switch to different directory with its own .venv, and then running uv pip install)

@charliermarsh charliermarsh self-assigned this Mar 20, 2024
@charliermarsh
Copy link
Member

Considering starting by showing the path if it's not .venv (i.e., a virtualenv in the current working directory).

@AlexWaygood
Copy link
Member

Considering starting by showing the path if it's not .venv (i.e., a virtualenv in the current working directory).

I think this would be really useful. I was just caught out by uv unexpectedly installing things into my ~dev/.venv environment, rather than my ~dev/project/env environment, because I didn't have the latter activated, and uv searched up through the directory structure until it found a virtual environment called .venv.

@ChannyClaus
Copy link
Contributor

ChannyClaus commented Apr 22, 2024

another separate, but related nicety would be printing out the Location column that pip list --verbose prints:

$ pip list --verbose
Package            Version     Location                                                            Installer
------------------ ----------- ------------------------------------------------------------------- ---------
asttokens          2.4.1       /Users/chankang/.pyenv/versions/3.12.2/lib/python3.12/site-packages uv
build              1.2.1       /Users/chankang/.pyenv/versions/3.12.2/lib/python3.12/site-packages uv

@zanieb zanieb added enhancement New feature or request tracing Verbose output and debugging and removed question Asking for clarification or support labels Jun 19, 2024
@zanieb zanieb added the good first issue Good for newcomers label Jul 1, 2024
@zanieb
Copy link
Member

zanieb commented Jul 1, 2024

I think it'd be reasonable to start with this: #2155 (comment)

@danielenricocahall
Copy link
Contributor

Hi! I wanted to look into this - would it be a matter of updating the line in uv/src/commands/pip/operations.rs to something like:

        writeln!(
            printer.stderr(),
            "{}",
            format!(
                "Installed {} in {} to {}",
                format!("{} package{}", wheels.len(), s).bold(),
                elapsed(start.elapsed()),
                venv.python_executable().display()
            )
            .dimmed()
        )?;

Based on the test results it looks correct (although it looks like we would need to update the snapshots)

Installed 3 packages in [TIME] to /private/var/folders/7s/q0mx5qbs78bfgpclqx_8tknm0000gn/T/.tmpRu7Vx5/.venv/bin/python3

@zanieb
Copy link
Member

zanieb commented Jul 4, 2024

We'd want to only display the path if it's not in the working directory which would require some sort of if/else. As a minor note, we use .user_display() for paths. Otherwise that seems like a reasonable place to start. Maybe we should print

Installing to environment at {path}

before this message instead of adding to the end of it?

@danielenricocahall
Copy link
Contributor

Sure! I have something like this:

        let python_executable = venv.python_executable();
        let venv_dir_canonical = fs::canonicalize(".venv").unwrap_or(PathBuf::from(".venv"));
        let is_outside_working_directory = !(python_executable.starts_with(&venv_dir_canonical));
        if is_outside_working_directory {
            writeln!(
                printer.stderr(),
                "{}",
                format!(
                    "Installing to environment at {}",
                    python_executable.user_display()
                )
            )?;
        }

I wasn't sure the best way to check for being in .venv so definitely open to suggestions there

@Aditya-PS-05
Copy link
Contributor

There are
1.) deleting packages
2.) updating packages
3.) resolving packages
4.) auditing packages
5.) installing packages

Should I print the path in every place or just at installing packages?
Which will be good practice?

@Aditya-PS-05
Copy link
Contributor

I am trying to print the path at every place where some changes in packaging is occuring.

This was referenced Sep 15, 2024
zanieb added a commit that referenced this issue Oct 2, 2024
Supersedes #4835

Closes #2155

e.g.

```
❯ cargo run -q -- pip install --python ../../example httpx
Using Python 3.12.1 environment at /Users/zb/example
Resolved 7 packages in 561ms
Prepared 4 packages in 62ms
Installed 4 packages in 13ms
 + certifi==2024.8.30
 + h11==0.14.0
 + httpcore==1.0.5
 + httpx==0.27.2

❯ cargo run -q -- pip install httpx
Resolved 7 packages in 17ms
Installed 4 packages in 10ms
 + certifi==2024.8.30
 + h11==0.14.0
 + httpcore==1.0.5
 + httpx==0.27.2
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers tracing Verbose output and debugging
Projects
None yet
8 participants