pip: pip 9.0.2 KeyError: 'pip._vendor.urllib3.contrib'

  • Pip version: 9.0.2
  • Python version: 2.7.3, 2.7.13
  • Operating system: Ubuntu 12.04, Ubuntu 16.04
In [1]: import urllib3.contrib

In [2]: import pip.pep425tags
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-2-9ae721442c45> in <module>()
----> 1 import pip.pep425tags

/home/<...>/.virtualenvs/other-sabt/local/lib/python2.7/site-packages/pip/__init__.py in <module>()
     43 from pip.utils import get_installed_distributions, get_prog
     44 from pip.utils import deprecation, dist_is_editable
---> 45 from pip.vcs import git, mercurial, subversion, bazaar  # noqa
     46 from pip.baseparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
     47 from pip.commands import get_summaries, get_similar_commands

/home/<...>/.virtualenvs/other-sabt/local/lib/python2.7/site-packages/pip/vcs/mercurial.py in <module>()
      7 from pip.utils import display_path, rmtree
      8 from pip.vcs import vcs, VersionControl
----> 9 from pip.download import path_to_url
     10 from pip._vendor.six.moves import configparser
     11 

/home/l<...>/.virtualenvs/other-sabt/local/lib/python2.7/site-packages/pip/download.py in <module>()
     38 from pip.locations import write_delete_marker_file
     39 from pip.vcs import vcs
---> 40 from pip._vendor import requests, six
     41 from pip._vendor.requests.adapters import BaseAdapter, HTTPAdapter
     42 from pip._vendor.requests.auth import AuthBase, HTTPBasicAuth

/home/<...>/.virtualenvs/other-sabt/local/lib/python2.7/site-packages/pip/_vendor/requests/__init__.py in <module>()
     96 
     97 from . import utils
---> 98 from . import packages
     99 from .models import Request, Response, PreparedRequest
    100 from .api import request, get, head, post, patch, put, delete, options

/home/<...>/.virtualenvs/other-sabt/local/lib/python2.7/site-packages/pip/_vendor/requests/packages.py in <module>()
     10     for mod in list(sys.modules):
     11         if mod == package or mod.startswith(package + '.'):
---> 12             sys.modules['pip._vendor.requests.packages.' + mod] = sys.modules["pip._vendor." + mod]
     13 
     14 # Kinda cool, though, right?

KeyError: 'pip._vendor.urllib3.contrib'

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I’m not sure if there’s any interest in maintaining the pip.main() as a passthrough command execution wrapper, but that could potentially mitigate the pain of upgrading.

I think this would make an excellent issue to discuss the relative merits of doing that (or not doing it).

I’m seeing the same thing with pip 9.0.2 while running on the python:3.6 docker container

  • pip version: 9.0.2
  • python version: 3.6.4
  • operating system: docker/linux

I’ve been able to narrow it down to occurring when the requests library is imported before the pip library. Here’s an example:

docker-user:~# python
Python 3.6.4 (default, Mar 14 2018, 17:49:05)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> import pip
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/pip/__init__.py", line 45, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/usr/local/lib/python3.6/site-packages/pip/vcs/mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "/usr/local/lib/python3.6/site-packages/pip/download.py", line 40, in <module>
    from pip._vendor import requests, six
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/__init__.py", line 98, in <module>
    from . import packages
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages.py", line 12, in <module>
    sys.modules['pip._vendor.requests.packages.' + mod] = sys.modules["pip._vendor." + mod]
KeyError: 'pip._vendor.urllib3.contrib'
>>> exit()
docker-user~# pip --version
pip 9.0.2 from /usr/local/lib/python3.6/site-packages (python 3.6)

The reverse works fine:

docker-user:~# python
Python 3.6.4 (default, Mar 14 2018, 17:49:05)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
>>> import requests
>>> print(pip)
<module 'pip' from '/usr/local/lib/python3.6/site-packages/pip/__init__.py'>