pip icon indicating copy to clipboard operation
pip copied to clipboard

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

Open tangculiji0612 opened this issue 3 years ago • 6 comments

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'

tangculiji0612 avatar Aug 08 '22 05:08 tangculiji0612

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?

ArshErgon avatar Aug 08 '22 06:08 ArshErgon

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.

domdfcoding avatar Aug 08 '22 07:08 domdfcoding

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

shanmukh9 avatar Aug 08 '22 15:08 shanmukh9

what is your pip version?

zhuofeng6 avatar Sep 01 '22 11:09 zhuofeng6

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:

  • Modify the error line /usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py 1895 adding the actual problem file to log:
    vi /usr/local/python3.7.5/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py +1895
    -         raise KeyError("No metadata except PKG-INFO is available")
    +         raise KeyError("No metadata except PKG-INFO is available: {}".format(self.path))
    
  • Then run again and check if the printed xxx.dist-info file valid. For mine it's caused by a broken soft link. Remove or rename that and try again.
  • You may also try if PYTHONPATH='' pip install sympy works.

leondgarse avatar Sep 05 '22 07:09 leondgarse