7

I am trying to create an isolated environment using pip, the instructions from "Hands on Machine Learning With Ski-Kit and Tensor Flow" have me run these lines of code and this is the output I get. I've tried uninstalling pipenv and that creates another error where pipenv command not found. Not sure how to work around this, can anyone help? I'm using a Mac with python3.9

Darrens-MacBook-Air:~ odonned4$ cd $ML_PATH

Darrens-MacBook-Air:~ odonned4$ virtualenv env

  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 'platformdirs<3,>=2' distribution was not found and is required by virtualenv```
0

3 Answers 3

8

What is the problem?

You are trying to run Python 3.9, right? Well, according to your error message, it seems like you're invoking Python 2.7:

File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>
                                                           ^^^

This confusion happens because macOS added Python 2.7 to the distribution for... compatibility reasons. And, probably, you have virtualenv on that distribution, but you don't have platformdirs, so creating a virtualenv fails.

How to solve the problem?

There are many ways to clarify this confusion. A good way is using python3 -m virtualenv (instead of virtualenv). That should create a virtualenv with Python 3.

Also, you can get sure that the virtualenv package is available in your Python 3.9 installation. To identify that, see if virtualenv appears when typing python3 -m pip list. If not, run python3 -m pip install virtualenv.

0
3

The real problem here is that Mac is hard wired to use python2. When using virtualenv, you might have run the command:

$ /usr/bin/easy_install virtualenv

which should have added virtualenv to the /usr/bin/ for direct use, but to be used with the default python2 instead of python3.9 which you might have installed on your own.

A simple way around is to use

$ python3 -m virtualenv <env-name>

instead of

$ virtualenv <env-name>

Or in my case, add an alias in .bash_profile:

$ alias virtualenv="python3 -m virtualenv"

which is a duct tape solution but it works as well.

0

Try uninstalling setuptools with

pip uninstall -y setuptools 

and reinstalling it with

pip install setuptools

OR

Upgrade setuptools with

pip install --upgrade setuptools

OR

For me i have faced this issue some before in python 3.8. I fixed it by

sudo apt install --reinstall python3-pkg-resources python3-setuptools

OR

Uninstall virtualenv and setuptools first and find pip cache folder.

pip cache dir

Delete the cache and install virtualenv and setuptools.

I JUST SAID SOME STEPS .. TRY THIS . MAY HELP : )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.