pip: pip19.0.1 list error"AttributeError: _version"

Environment

  • pip version:19.0.1
  • Python version:3.7
  • OS:MacOS

I update pip from 10.1 to 19.0.1, and I wanna check my python packages, I input “pip list” then two errors occurred. Description

Expected behavior

Exception: Traceback (most recent call last): File “/usr/local/var/pyenv/versions/3.7.0/lib/python3.7/site-packages/pip/_vendor/pkg_resources/init.py”, line 2584, in version return self._version File “/usr/local/var/pyenv/versions/3.7.0/lib/python3.7/site-packages/pip/_vendor/pkg_resources/init.py”, line 2691, in getattr raise AttributeError(attr) AttributeError: _version

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “/usr/local/var/pyenv/versions/3.7.0/lib/python3.7/site-packages/pip/_internal/cli/base_command.py”, line 176, in main status = self.run(options, args) File “/usr/local/var/pyenv/versions/3.7.0/lib/python3.7/site-packages/pip/_internal/commands/list.py”, line 148, in run self.output_package_listing(packages, options) File “/usr/local/var/pyenv/versions/3.7.0/lib/python3.7/site-packages/pip/_internal/commands/list.py”, line 205, in output_package_listing data, header = format_for_columns(packages, options) File “/usr/local/var/pyenv/versions/3.7.0/lib/python3.7/site-packages/pip/_internal/commands/list.py”, line 271, in format_for_columns row = [proj.project_name, proj.version] File “/usr/local/var/pyenv/versions/3.7.0/lib/python3.7/site-packages/pip/_vendor/pkg_resources/init.py”, line 2589, in version raise ValueError(tmpl % self.PKG_INFO, self) ValueError: (“Missing ‘Version:’ header and/or METADATA file”, Unknown [unknown version] (/usr/local/var/pyenv/versions/3.7.0/lib/python3.7/site-packages)) How to Reproduce

  1. Get package from ‘…’
  2. Then run ‘…’
  3. An error occurs.

Output

Paste the output of the steps above, including the commands themselves and
pip's output/traceback etc.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 11
  • Comments: 32 (13 by maintainers)

Commits related to this issue

Most upvoted comments

These don’t look right… ./pocketsphinx-0.1.3.dist-info/pocketsphinx-0.1.3.dist-info/METADATA ./-rpcio-1.18.0.dist-info/grpcio-1.18.0.dist-info/METADATA

@AnonGuy thanks a lot 🙌🏼 -rpcio with a dash was making the problem…

Same for me a package with a dash was the culprit.

Maybe someone can file an issue there.

Did that: https://github.com/pypa/setuptools/issues/1664

To identify offending packages, I ran the following inside the site-packages directory:

import os
import re
for roots, dirs, files in os.walk("."):
    if re.match(".*dist-info", roots):
        if "METADATA" not in files:
            print(roots)

Then removed the offending directories and reinstalled their packages.

These don’t look right…

./pocketsphinx-0.1.3.dist-info/pocketsphinx-0.1.3.dist-info/METADATA
./-rpcio-1.18.0.dist-info/grpcio-1.18.0.dist-info/METADATA

Fixed by removing a folder called -umpy-1.15.4.dist-info from site-packages.

The cause for a lot of these was fixed in version 19.0.2, which is why this issue was closed. However, people might still be experiencing this issue because of directories that were corrupted before (or getting corrupted for a completely different reason). Subscribe to issue #6283 for more graceful handling of these directories, and for suggestions on how to remove a corrupted directory you might have.

@0000matteo0000 Does this fix your issue?

mv pocketsphinx-0.1.3.dist-info p; mv p/pocketsphinx-0.1.3.dist-info .; rm -r p
mv -rpcio-1.18.0.dist-info r; mv r/grpcio-1.18.0.dist-info .; rm -r r

yup thanks, i moved those and i had to also move pip itself but that fixed it it seems, could there be a bug in pip so that packages are put in the wrong folders? because i never moved anything around there

@0000matteo0000 Does this fix your issue?

mv pocketsphinx-0.1.3.dist-info p; mv p/pocketsphinx-0.1.3.dist-info .; rm -r p
mv -rpcio-1.18.0.dist-info r; mv r/grpcio-1.18.0.dist-info .; rm -r r

I got the same problem in my mac. The original pip was installed along with python3 through brew install python3 and works well. After i tried to update pip by pip3 install -U pip , pip commands(pip list) start to raise those exceptions. The discussion above give me a hint to check whether broken project exists in my site-packages folder or not.

  • Since pip --version shows pip 19.0.1 from /usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip (python 3.6), i went into the folder and tried to find some folders starting with ‘-’ with no luck.
  • It is frustrating that the error message is not enough to locate the exact problem, so i decided to debug it to get details, …, here we go:
#pip/_vendor/pkg_resources/__init__.py
    @property
    def version(self):
        try:
            print('-'*50)
            print(self.project_name)
            print(self.location)
            print(self._version)
            # print(self.project_name, self._version, self.location)
            return self._version
        except AttributeError:
            version = _version_from_file(self._get_metadata(self.PKG_INFO))
            if version is None:
                print('Something wrong exists in:', self.project_name)
                tmpl = "Missing 'Version:' header and/or %s file"
                raise ValueError(tmpl % self.PKG_INFO, self)
            return version

then pip list outputs:

. . .
--------------------------------------------------
Unknown
/Users/king/Library/Python/3.6/lib/python/site-packages
Something wrong exists in Unknown

I realized that broken packages may exist in /Users/king/Library/Python/3.6/lib/python/site-packages and it does in fact. After i remove broken packages in this folder, pip comes back to life!

I am also getting some error using pip freeze. I am using windows 10, python 3.6.0 and pip version is 19.0.1. Please take a look:

`Error checking for conflicts.
Traceback (most recent call last):
  File "c:\users\rohit\appdata\local\programs\python\python36\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2584, in version
    return self._version
  File "c:\users\rohit\appdata\local\programs\python\python36\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2691, in __getattr__
    raise AttributeError(attr)
AttributeError: _version

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\rohit\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\commands\install.py", line 503, in _warn_about_conflicts
    package_set, _dep_info = check_install_conflicts(to_install)
  File "c:\users\rohit\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\operations\check.py", line 108, in check_install_conflicts
    package_set, _ = create_package_set_from_installed()
  File "c:\users\rohit\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\operations\check.py", line 47, in create_package_set_from_installed
    package_set[name] = PackageDetails(dist.version, dist.requires())
  File "c:\users\rohit\appdata\local\programs\python\python36\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2589, in version
    raise ValueError(tmpl % self.PKG_INFO, self)
ValueError: ("Missing 'Version:' header and/or METADATA file", Unknown [unknown version] (c:\users\rohit\appdata\local\programs\python\python36\lib\site-packages))`

Any help will be appreciated.