I installed Python, pip3, and virtualenv as in this guide for TensorFlow:

brew install python
pip3 install -U virtualenv

Then I was able to create a virtual environment with:

virtualenv --system-site-packages -p python3 ./venv

Then I tried installing TensorFlow with

pip install --upgrade tensorflow

but it failed because TensorFlow is not yet compatible with Python 3.7. So I removed Python 3.7 with brew remove python and installed 3.6.7 from an installer. But running the same virtualenv command now fails:

$ virtualenv --system-site-packages -p python3 ./venv
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory
$ which python3

So the virtualenv link to the executable lists the newest Python version, even after removal.

Furthermore, virtualenv lists brew as the user group, which is also confusing:

$ ls -la /usr/local/bin/virtualenv
-rwxr-xr-x  1 user  brew  232 29 Nov 17:06 /usr/local/bin/virtualenv

I've tried uninstalling virtualenv with both pip and pip3 and I get:

Skipping virtualenv as it is not installed.

How can I fix this issue?


After a few hours, one solution was to install virtualenv again with pip, then remove it with pip:

$ ls -la /usr/local/bin/virtualenv
-rwxr-xr-x  1 user  brew  232 29 Nov 17:06 /usr/local/bin/virtualenv
$ pip install virtualenv
$ pip uninstall virtualenv
$ which virtualenv
$ ls -la /usr/local/bin/virtualenv
ls: /usr/local/bin/virtualenv: No such file or directory

And then install it again with pip3:

$ pip3 install virtualenv
Collecting virtualenv
Installing collected packages: virtualenv
Successfully installed virtualenv-16.1.0

Notice the use of pip3, and not pip, unlike this link, pointed to by TensorFlow.

And now creating the virtual environment works:

$ virtualenv --system-site-packages -p python3 ./venv
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in ~/venv/bin/python3
Also creating executable in ~/venv/bin/python
Installing setuptools, pip, wheel...

I created a symlink instead of copy.

brew install python@3.7
ln -s /usr/local/opt/python@3.7/bin/python3.7 /usr/local/opt/python/bin/python3.7
  • Thanks a lot! That worked like a charm! – Byron Jan 18 at 11:48

In my case, I had installed pipenv on MacOS with:

brew install pipenv

It was trying to use Python 3.6 instead of the 3.7 I actually had.

So I solved the issue by uninstalling:

brew uninstall pipenv

...then installing again with pip:

pip3 install pipenv
  • doesn't work for me. I'm using asdf and an existing pipenv installation. – Harry Moreno Jul 24 '20 at 3:17

Try installing python@3.7 via homebrew and then cping that installation into the directory the program expects to find it.

brew install python@3.7
cp -r /usr/local/opt/python@3.7/bin/python3.7 /usr/local/opt/python/bin/python3.7

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.