uv icon indicating copy to clipboard operation
uv copied to clipboard

Add `uv pip list`

Open zanieb opened this issue 1 year ago • 7 comments

This is a really helpful command :)

zanieb avatar Feb 16 '24 00:02 zanieb

Yes please! :)

matthewfeickert avatar Feb 16 '24 04:02 matthewfeickert

Wow I'm so used to pip freeze, no idea why!

Is it important we follow the exact same format? Do people read this programmatically?

charliermarsh avatar Feb 16 '24 04:02 charliermarsh

Maybe this can help? https://github.com/pypa/pip/pull/752

Tarliton avatar Feb 16 '24 04:02 Tarliton

Is it important we follow the exact same format? Do people read this programmatically?

Hm, good question. Problably not required to have the exact same output, but I think plenty of people are doing grep/awk/sed stuff on the output of pip list (I know I am).

@charliermarsh as to why pip list when pip freeze exists, I would say the spacing choices are more (quickly) human readable and having the two column structure allows for parsing of package (not version) easier.

$ docker run --rm -ti python:3.12 /bin/bash
root@4106918bf8c2:/# python -m venv venv && . venv/bin/activate
(venv) root@4106918bf8c2:/# python -m pip --quiet install awkward
(venv) root@4106918bf8c2:/# python -m pip list
Package     Version
----------- --------
awkward     2.6.1
awkward-cpp 29
fsspec      2024.2.0
numpy       1.26.4
packaging   23.2
pip         24.0
(venv) root@4106918bf8c2:/# python -m pip freeze
awkward==2.6.1
awkward-cpp==29
fsspec==2024.2.0
numpy==1.26.4
packaging==23.2
(venv) root@4106918bf8c2:/#

For me, pip list is the goto and as an example of how I use it also programatically, here's how I clean up my virtual environment so that I can have clean installs when I'm updaing my GPU support enabled JAX environment

#!/bin/bash

python -m pip list | grep 'jax\|nvidia\|ml-dtypes' | awk '{print $1}' | xargs python -m pip uninstall --yes
python -m pip list

JAX_VERSION=0.4.24

# CUDA_VERSION=11
CUDA_VERSION=12

CUDA_DISTRIBUTION="pip"
# CUDA_DISTRIBUTION="local"

python -m pip install --upgrade "jax[cuda${CUDA_VERSION}_${CUDA_DISTRIBUTION}]==${JAX_VERSION}" --find-links https://storage.googleapis.com/jax-releases/jax_cuda_releases.html

python -m pip list | grep jax

echo ""
python jax_detect_GPU.py

matthewfeickert avatar Feb 16 '24 04:02 matthewfeickert

Funny, I didn't know we had a freeze command 😶‍🌫️

zanieb avatar Feb 16 '24 05:02 zanieb

pip list --outdated is also a useful feature.

ismail avatar Feb 16 '24 07:02 ismail

pip list also shows editable install locations (if any) as compared to pip freeze.

jab avatar Feb 17 '24 15:02 jab

There is also the --format option you might want to support.

--format <list_format> Select the output format among: columns (default), freeze, or json. The 'freeze' format cannot be used with the --outdated option.

Then you could do uv pip list --format=freeze. The json format could be good for people who read this programmatically.

jlhamilton777 avatar Feb 26 '24 02:02 jlhamilton777

Is --format=freeze different than pip freeze?

This was added in https://github.com/astral-sh/uv/pull/1662 so I'm going to close this now. We can track output formats in a new issue.

zanieb avatar Feb 26 '24 04:02 zanieb

Is --format=freeze different than pip freeze?

(uvtest) C:\Users\User\Desktop\uvtest> python -m pip list --format freeze
pip==24.0
setuptools==68.0.0
uvtest==0.1.0
wheel==0.42.0

(uvtest) C:\Users\User\Desktop\uvtest> python -m pip freeze
# Editable Git install with no remote (uvtest==0.1.0)
-e c:\users\user\desktop\uvtest

Yes, they are different, but I'd like to pip list --format freeze supersede pip freeze. tracked in #1970.

T-256 avatar Feb 26 '24 11:02 T-256