question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pip>=20.2 needlessly re-installs dependencies available on the system in system-site-packages venv

See original GitHub issue

What did you want to do?

We are using a venv that explicitly does use system-site-packages, in order to allow users in a container, which does not allow write access to /, to install their own packages while still using all the (partially very complex to install/build) packages provided by the container image. This used to work fine until pip>=20.2, and is still broken in latest pip dev build as of today.

Output

Singularity> python3 -m venv --system-site-packages test_venv
Singularity> source ./test_venv/bin/activate
(test_venv) Singularity> pip list | grep numpy
numpy              1.19.1
WARNING: You are using pip version 20.1.1; however, version 20.2.1 is available.
You should consider upgrading via the '/home/users/fmaussion/test_venv/bin/python3 -m pip install --upgrade pip' command.
(test_venv) Singularity> pip install numpy
Requirement already satisfied: numpy in /usr/local/pyenv/versions/3.7.8/lib/python3.7/site-packages (1.19.1)
WARNING: You are using pip version 20.1.1; however, version 20.2.1 is available.
You should consider upgrading via the '/home/users/fmaussion/test_venv/bin/python3 -m pip install --upgrade pip' command.
(test_venv) Singularity> pip install --upgrade pip setuptools
Collecting pip
  Using cached pip-20.2.1-py2.py3-none-any.whl (1.5 MB)
Collecting setuptools
  Using cached setuptools-49.2.1-py3-none-any.whl (789 kB)
Installing collected packages: pip, setuptools
  Attempting uninstall: pip
    Found existing installation: pip 20.1.1
    Uninstalling pip-20.1.1:
      Successfully uninstalled pip-20.1.1
  Attempting uninstall: setuptools
    Found existing installation: setuptools 47.1.0
    Uninstalling setuptools-47.1.0:
      Successfully uninstalled setuptools-47.1.0
Successfully installed pip-20.2.1 setuptools-49.2.1
(test_venv) Singularity> pip install numpy
Collecting numpy
  Using cached numpy-1.19.1-cp37-cp37m-manylinux2010_x86_64.whl (14.5 MB)
Installing collected packages: numpy
Successfully installed numpy-1.19.1

As you can see, before updating pip to 20.2, it correctly notices that numpy is already installed and does not need to do anything. After the update, it goes and installs a copy of the same numpy version in the venv. The same happens when installing a package that depends on numpy. Also the same goes for any other dependency that’s already provided by the system site-packages. “pip list” correctly lists numpy as installed in either case.

Additional information

The reason we are doing it this way is because building some of those dependencies, which are binary and annoying to deal with (most prominently gdal and fiona). The singularity container image has all of them pre-built, with optimizations specific for the host systems CPU.

For now I’ve instructed users to either use --no-deps when installing things, or to explicitly pin pip to <20.2.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
sbidoulcommented, Aug 6, 2020

@fdebrabander the issue is fixed in #8702 and should be part of the next patch release. You can test it by installing that branch with pip install -U "pip @ git+https://github.com/pypa/pip@refs/pull/8702/head".

1reaction
sbidoulcommented, Aug 4, 2020

This is due to the local_only argument of search_distributions that is True by default when called from utils.misc.get_distribution().

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pip won't install packages in Venv that are also in system site ...
When I activate my virtual environment and call pip list --local , I get a list of all my system-site-packages rather than the...
Read more >
Installation — Flask Documentation (1.1.x)
Flask supports Python 3.5 and newer, Python 2.7, and PyPy. Dependencies¶. These distributions will be installed automatically when installing Flask. Werkzeug ...
Read more >
Developer Setup — Mu 1.2.0 documentation
Create a working development environment by installing all the dependencies into your virtualenv with: pip install -e ".[dev]".
Read more >
Python Virtual Environments: A Primer
In this tutorial, you'll learn how to work with Python's venv module to create and manage separate virtual environments for your Python ...
Read more >
venvtools - PyPI
A simple setuptools command to help with virtualenv. ... Make the system (global) site-packages dir available to the created environment.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found