In some cases, this can occur because pip was upgraded by the root user, and the upgrade - for some reason - defaults to creating non-all-user-accessible subdirectories and files in the "site-packages" directory.
To check if this is the case, we need locate the site-packages directory, e.g. with python3, running this command:
python -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])'
Now let's check whether there are pip-related subdirs there with problematic permissions:
site_pkg_dirs=$(python -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')
pushd ${site_pkg_dirs}
ls -ld pip*
popd
If the output is empty - then this answer won't solve your problem; sorry :-(
But if the output is not empty, e.g.:
drwxr-x--- 5 root root 111 Jan 01 00:00 pip
drwxr-x--- 2 root root 170 Jan 01 00:00 pip-21.3.1.dist-info
then carefully examine the permission listing on each: If the "all" permission triplet doesn't have r
and x
- you need to add those; and since this same problem might be manifested for other packages, let's be more thorough about it:
find ${site_pkg_dirs} -type d | chmod a+rx
find ${site_pkg_dirs} -type f | chmod a+r
this ensures all subdirectories in your site package directory are readable and recursable, and that all files in those subdirectories are readable. Specifically, this will apply to the pip-related subdirs, which should now look like this when you ls -l
them:
drwxr-xr-x 5 root root 111 Jan 01 00:00 pip
drwxr-xr-x 2 root root 170 Jan 01 00:00 pip-21.3.1.dist-info
This should solve your pip troubles! Let's check: If you now run
pip show pip
you should get something like :
$ pip3.6 show pip
Name: pip
Version: 21.3.1
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: distutils-sig@python.org
License: MIT
Location: /usr/lib/python/site-packages
Requires:
Required-by:
possibly with a different version and your own site packages dir.