Python – ImportError: cannot import name ContextualZipFile

I bumped into an error while installing pip in my Mac system and it took me couple of hours to get it resolved. In this article, I will explain the error details and how I was able to resolve it.


If you are using Mac, an easy way to install pip is by using easy_install —

$ sudo easy_install pip

However when I ran this command I got an error — ‘ImportError: cannot import name ContextualZipFile’

Traceback (most recent call last):
File “/usr/bin/easy_install-2.7”, line 11, in <module>
load_entry_point(‘setuptools==18.5’, ‘console_scripts’, ‘easy_install’)()
File “/Users/sbehara1/Library/Python/2.7/lib/python/site-packages/pkg_resources/”, line 480, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File “/Users/sbehara1/Library/Python/2.7/lib/python/site-packages/pkg_resources/”, line 2693, in load_entry_point
return ep.load()
File “/Users/sbehara1/Library/Python/2.7/lib/python/site-packages/pkg_resources/”, line 2324, in load
return self.resolve()
File “/Users/sbehara1/Library/Python/2.7/lib/python/site-packages/pkg_resources/”, line 2330, in resolve
module = __import__(self.module_name, fromlist=[‘__name__’], level=0)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/”, line 46, in <module>
from setuptools.archive_util import unpack_archive
File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/”, line 15, in <module>
from pkg_resources import ensure_directory, ContextualZipFile
ImportError: cannot import name ContextualZipFile

Looking at the, I could find the problematic ‘ContextualZipFile’ and most probably the root cause of this issue. It somehow seems that I have an older version of setuptools (or just pkg_resources) in my system site packages, and somehow that’s interfering. Upgrading the setuptools is potentially a resolution here.


Pip can be installed in multiple ways — either through your system package manager or through  ensurepip or through the bootstrap module.
setuptools distribution actually provides two packages (pkg_resources and setuptools). You will need to make sure that you install these 2 packages from a single process.

The ensurepip package provides support for bootstrapping the pip installer into an existing Python installation or virtual environment.
The command line interface is invoked using the interpreter’s -m switch. Running the below command worked for me and pip was successfully installed —

$ sudo -H python -m ensurepip

After pip was successfully installed, I noticed that the pkg_resources and setuptools were updated —


I looked at the and did not find the ‘ContextualZipFile’ —


Give this a shot and let me know if this fixes your problem.


Start a 10-day FREE trial at Pluralsight – Over 5,000 courses available

Pluralsight Logo

Categories: Python

3 replies

  1. I have the same issue, but running “sudo -H python -m ensurepip” did not help. Any other ideas?


  2. bravo …. ! save my day buddy you are rock (Y)

    Liked by 1 person

  3. thank u man! You save me!

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: