uv: `uv pip` does not read all system packages (e.g., in `uv pip list --system` or virtual environments with `system-site-packages`)
Executing uv pip list --system does not list any packages. Similarly for freeze and show subcommands (I did not test any others).
$ uv pip list --system -vv
uv_interpreter::find_python::find_default_python
0.000148s 0ms DEBUG uv_interpreter::find_python Starting interpreter discovery for default Python
0.000319s 0ms DEBUG uv_interpreter::interpreter Cached interpreter info for Python 3.12.2, skipping probing: /usr/bin/python3
0.000334s DEBUG uv::commands::pip_list Using Python 3.12.2 environment at /usr/bin/python3
OS: Fedora 39, python 3.12, amd64 uv version: 0.1.21, installed via pipx
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 6
- Comments: 33 (29 by maintainers)
Commits related to this issue
- add `sys_path` to `Interpreter` struct (#3500) <!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary of ... — committed to astral-sh/uv by ChannyClaus 3 years ago
- Include environment variables in interpreter info caching We want to use `sys.path` for package discovery (#2500, #9849). For that, we need to know the correct value of `sys.path`. `sys.path` is a ru... — committed to astral-sh/uv by konstin 2 years ago
- Include environment variables in interpreter info caching We want to use `sys.path` for package discovery (#2500, #9849). For that, we need to know the correct value of `sys.path`. `sys.path` is a ru... — committed to astral-sh/uv by konstin 2 years ago
- Include environment variables in interpreter info caching (#11601) We want to use `sys.path` for package discovery (#2500, #9849). For that, we need to know the correct value of `sys.path`. `sys.path... — committed to astral-sh/uv by konstin 2 years ago
- Revert: Include environment variables in interpreter info caching (#11622) Revert #11601 for now We run Python interpreter discovery with `-I` (#2500) which means these environments variables are ig... — committed to astral-sh/uv by konstin 2 years ago
- Include environment variables in interpreter info caching (#11601) We want to use `sys.path` for package discovery (#2500, #9849). For that, we need to know the correct value of `sys.path`. `sys.path... — committed to loic-lescoat/uv by konstin 2 years ago
- Revert: Include environment variables in interpreter info caching (#11622) Revert #11601 for now We run Python interpreter discovery with `-I` (#2500) which means these environments variables are ig... — committed to loic-lescoat/uv by konstin 2 years ago
I just ran into a variant of this problem when working with layered environments that use
sitecustomize.pyto incorporate additional shared folders: whenuvis installing into the upper environments, it fails to detect the packages that are already installed in the lower layers. (My use case is along the same lines as the HPC use case above: shared layers with big dependencies preinstalled, then smaller application environments built on top of that)I initially thought it was working correctly because
uv pip installis so much faster thanpip install, but the problem became clear when archiving the upper layers slowed down dramatically (unexpectedly including additional copies oftorchandnvidia-cudain an archive is… not great).Between
*.pthfiles andsitecustomize.py, the only reliable way to find out what packages a Python environment can currently see installed is to ask it for itssys.pathvalue and scan every entry in order, it simply isn’t correct to assume that the only directories that matter are the ones where installation tools are told to put new components.Running
python -m siteis a useful way of dumping the relevantsys.pathinfo when investigating problems along these lines (althoughpython -c "import sys; print(sys.path)"is better for programmatic use, as was done in #3500).Using
sitecustomize.pyfiles to reproduce the problem should be much easier to manage in test cases than relying specifically on Linux distro Python builds that add extra directories tosys.path.I don’t advise trying to use
*.pthfiles (even in test cases), since they have problems dealing with non-ASCII paths in Python versions prior to 3.13.Edit: for anyone curious, the specific environment layering project referred to here is https://pypi.org/project/venvstacks/
@ChannyClaus to clarify, this has always worked. 😃 In other words, this issue is about uv ignoring Fedora system packages that come with the Fedora installation, which are in a different directory from system packages installed by the user. (I am assuming they are doing this to prevent users from messing up the system python install).
I’d still argue that uv should list all the packages that are available to the Python interpreter.
I noticed the following help text for the
uv venv --system-site-packagesThis is very much the same issue as here, but from the text it is not clear whether this was a conscious design decision or just stating the current limitation. If the former I’d argue to reconsider. As an example, in HPC context, admins may provide a base Python environment with basic scientific packages (numpy et al) compiled specifically for the machine to get the best performance. In this case, it would be quite wrong for uv to ignore these packages and reinstall them inside the venv.
For the test suite, I’d recommend testing the
sitecustomize.pycase rather than thesystem-site-packagescase:sitecustomize.pyfile intosite-packagesthat usessite.addsitedirto integrate thesite-packagesfolder from environment A into environment Blist/show/freezecan see the packages in both environmentspip uninstallhandles this case, but refusing to uninstall seems preferable no matter whatpipdoes)If that works as described, a venv with system-site-packages enabled should also work (without the hassle of trying to make tests that enable system-site-packages portable across different Python installations).
i can probably look into this sometime this week (maybe weekend) unless someone else is already on it :.)
things may have changed significantly since this was months ago but the main change necessary was https://github.com/astral-sh/uv/pull/2636/files#diff-f29dcb297374a7babe6be50ec410d36c52cb44c6e9ec5183b4b7d0b96229bd94R94-R109 i believe 🌵
(To summarize, I think the fix here is to iterate over
sys.paths(probably) instead of just looking atpurelibandplatlib.)Hmm, strange. I am running directly on Fedora 39, I am wondering if there are some differences between Fedora 39 Docker image and normal install. Also in your case you’re running under root, not sure if that makes a difference. I’ll try to dig around a bit more.
Indeed, installing something into system packages will install it to
/usr/local/libHere’s how the site directories are configured in my Python (Fedora 39)
Yep, that seems to be the case.