How do I fix this error "DistributionNotFound: The 'zipp>=0.5' distribution was not found and is required by importlib-metadata"?

Chris Hangsun Kim picture Chris Hangsun Kim · Feb 26, 2020 · Viewed 8.8k times · Source

I'm tying to create a virtual environment in my mac terminal and I get the following error. Could you please help me how I can fix this?

hangsunkim@Hangs-MacBook-Pro ~ % virtualenv --system-site-packages -p python3 ./venv
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>
    @_call_aside
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_aside
    f(*args, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 585, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 598, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'zipp>=0.5' distribution was not found and is required by importlib-metadata

Answer

mathias.lantean picture mathias.lantean · Mar 13, 2020

macOS Catalina --> Version 10.15.3

python --version --> Python 3.7.7

pip --version --> pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

After a while trying to install virtualenv and virtualenvwrapper I figured out how to make them work.

Here is what I did:

  1. Install python 3
    brew update && brew upgrade
    brew doctor

You should see something like "Your system is ready to brew."

    brew install python
  1. Use python 3 for default. You must add this line to your .zshrc file (if this file doesn't exist just create it).
    # Add user python 3.7 to path
    export PATH="/usr/local/opt/python/libexec/bin:$PATH"
  1. Install virtualenv and virtualenvwrapper
    pip install virtualenv
    pip install virtualenvwrapper
  1. Add virtualenvwrapper settings to .zshrc file (if you don't know where is virtualenvwrapper.sh located just do which virtualenvwrapper.sh)
    #Virtualwrapper stuff
    export WORKON_HOME=$HOME/.virtualenvs
    export PROJECT_HOME=$HOME/Git
    source /usr/local/bin/virtualenvwrapper.sh

At this point, we still have the zipp>=0.5' error. So what is the problem? As you see in your traceback, virtualenv is trying to use the python version installed in the system and is in that place where there is no distribution of zipp.

I don't know if it is the best way to fix this but at least I was able to create virtualenvs after this:

  1. sudo su
  2. Install pip with system python (you must download the get-pip.py file)
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python /Users/{your_username}/Desktop/get-pip.py 
  1. Install again virtualenv and virtualenvwrapper (in sudo mode)
    pip install virtualenv
    pip install virtualenvwrapper
  1. Exit sudo mode. As a normal user I tried to install again virtualenv and virtualenvwrapper and after that restarted the terminal (I don't know if it's necessary but just in case).
  2. Finally, try to create your virtualenv mkvirtualenv test