Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cryptic error when a dependency's PKG_INFO/METADATA is missing #5082

nvictus opened this issue Mar 18, 2018 · 4 comments

Cryptic error when a dependency's PKG_INFO/METADATA is missing #5082

nvictus opened this issue Mar 18, 2018 · 4 comments


Copy link

@nvictus nvictus commented Mar 18, 2018

  • Pip version: 9.0.1
  • Python version: 3.6.4
  • Operating system: Ubuntu 17.10


Pip crashes with a cryptic error when it doesn't find a dependency's package metadata.

What I've run:

A certain dependency was installed using conda and was lacking a PKG-INFO file in the egg-info. When installing the desired package, pip fails right after processing the dependency with this error traceback:

Traceback (most recent call last):
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/", line 215, in main
    status =, args)
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/commands/", line 335, in run
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/", line 756, in build
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/req/", line 380, in prepare_files
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/req/", line 666, in _prepare_file
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/utils/", line 48, in check_dist_requires_python
  File "/home/nezar/miniconda3/lib/python3.6/email/", line 175, in feed
  File "/home/nezar/miniconda3/lib/python3.6/email/", line 103, in push
TypeError: string argument expected, got 'NoneType'

On inspecting pip/utils/

def get_metadata(dist):
    if (isinstance(dist, pkg_resources.DistInfoDistribution) and
        return dist.get_metadata('METADATA')
    elif dist.has_metadata('PKG-INFO'):
        return dist.get_metadata('PKG-INFO')

def check_dist_requires_python(dist):
    metadata = get_metadata(dist)
    feed_parser = FeedParser()
    pkg_info_dict = feed_parser.close()
    requires_python = pkg_info_dict.get('Requires-Python')
        if not check_requires_python(requires_python):
            raise exceptions.UnsupportedPythonVersion(
                "%s requires Python '%s' but the running Python is %s" % (
                    '.'.join(map(str, sys.version_info[:3])),)
    except specifiers.InvalidSpecifier as e:
            "Package %s has an invalid Requires-Python entry %s - %s" % (
                dist.project_name, requires_python, e))

get_metadata is returning None when it doesn't find anything, which causes feed_parser to crash.

Copy link

@pradyunsg pradyunsg commented Nov 10, 2018

@cytolentino Hi!

Could you take a look at this issue? There should probably be a conditional somewhere, that prevents us from passing None to feed_parser, aborting early. :)


Copy link

@cytolentino cytolentino commented Nov 11, 2018

Hi @pradyunsg! I've just had a look at this and it seems like someone else has already fixed this (see here). That said, I've added in a regression test for this case to confirm that it's fixed over here: PR #6003 :)


Copy link

@cjerdonek cjerdonek commented May 26, 2019

Marking this as a bug because pip shouldn't necessarily be crashing here (at least sometimes I don't think).


Copy link

@cjerdonek cjerdonek commented May 26, 2019

I posted a fix for this (PR #6542). However, I only addressed the "enhancement" aspect (better error message) because in working on the patch I found that it should probably continue to error out (at least for now).

If there are other get_metadata() callers in the code base that shouldn't be erroring out in this situation, that should probably be handled on a case-by-case basis in different issues (when they are filed). There are many callers of get_metadata(), so I don't think we'd want to do a blanket "fix."


@lock lock bot added the S: auto-locked label Jun 26, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants