3

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
anthony sottile
  • 61,815
  • 15
  • 148
  • 207

4 Answers4

6

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
Community
  • 1
  • 1
mathias.lantean
  • 541
  • 4
  • 10
6

First uninstall the virtualenv

sudo pip uninstall virtualenv

Then find the pip cache directory using:

pip cache dir

Now delete this cache using rm -rf:

rm -rf above_cache_directory

Find the remaining directories of virtualenv using which and delete them:

which virtualenv
rm -rf above_found_directory

Now install virtualenv again:

sudo pip install virtualenv
Arihant
  • 660
  • 6
  • 9
0

Also, not sure it's the best answer but building off mathias's answer you could use an alias to point at a pip3 install version.

pip3 install -U virtualenv
VERSION=$(python3 --version| sed -En 's/[^[:digit:]]*([[:digit:]]+)[^[:digit:]]+([[:digit:]])[^[:digit:]]./\1.\2/p')
echo 'alias virtualenv="/Library/Frameworks/Python.framework/Versions/'$VERSION'/bin/virtualenv"' >> /Users/$USER/.zshrc
source ~/.zshrc
Cynic
  • 6,779
  • 2
  • 30
  • 49
0

Use this command:

$ source nameofthefolder/bin/activate
Robson
  • 813
  • 5
  • 21
  • 40