pypa / pip

The Python package installer
https://pip.pypa.io/
MIT License
9.45k stars 3k forks source link

KeyError: 'No metadata except PKG-INFO is available' #11361

Open tangculiji0612 opened 2 years ago

tangculiji0612 commented 2 years ago

I made an error when executing the PIP install command:

root@ubuntu:~# pip install sympy
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple, https://pypi.ngc.nvidia.com
Collecting sympy
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d0/04/66be21ceb305c66a4b326b0ae44cc4f027a43bc08cac204b48fb45bb3653/sympy-1.10.1-py3-none-any.whl (6.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.4/6.4 MB 2.1 MB/s eta 0:00:00
Requirement already satisfied: mpmath>=0.19 in /usr/local/python3.7.5/lib/python3.7/site-packages (from sympy) (1.2.1)
ERROR: Error while checking for conflicts. Please file an issue on pip's issue tracker: https://github.com/pypa/pip/issues/new
Traceback (most recent call last):
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3021, in _dep_map
    return self.__dep_map
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2815, in __getattr__
    raise AttributeError(attr)
AttributeError: _DistInfoDistribution__dep_map

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3012, in _parsed_pkg_info
    return self._pkg_info
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2815, in __getattr__
    raise AttributeError(attr)
AttributeError: _pkg_info

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 585, in _determine_conflicts
    return check_install_conflicts(to_install)
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_internal/operations/check.py", line 101, in check_install_conflicts
    package_set, _ = create_package_set_from_installed()
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_internal/operations/check.py", line 42, in create_package_set_from_installed
    dependencies = list(dist.iter_dependencies())
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_internal/metadata/pkg_resources.py", line 199, in iter_dependencies
    return self._dist.requires(extras)
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2736, in requires
    dm = self._dep_map
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3023, in _dep_map
    self.__dep_map = self._compute_dependencies()
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3032, in _compute_dependencies
    for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3014, in _parsed_pkg_info
    metadata = self.get_metadata(self.PKG_INFO)
  File "/usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1895, in get_metadata
    raise KeyError("No metadata except PKG-INFO is available")
KeyError: 'No metadata except PKG-INFO is available'
ArshErgon commented 2 years ago

does this error happen when you try to install any other library other than your current one? Could you try to uninstall python and reinstall it?

domdfcoding commented 2 years ago

It looks like you're trying to install the package globally (which generally isn't a good idea). Can you try installing into a virtual environment (see the guide here if you're unsure) to see if the problem persists.

shanmukh9 commented 2 years ago

can you try to upgrade your pip to pip3 and try?

zhuofeng6 commented 1 year ago

what is your pip version?

leondgarse commented 1 year ago

I came across this issue today, and my pip version is pip 22.2.2. For me it's any pip command like pip show numpy also throwing this error. My solution is:

pradyunsg commented 3 months ago

This is an error that's only happening on < 3.10, since pip will will use a different metadata backend than pkg_resources on Python 3.10+.