Fix virtualenv after installing python 3 with brew

homebrewpython

Previously I had the default Python 2.7, and I have a lot of virtualenvs created under python 2, using virtualenvwrapper. Recently, I wanted to be able to use python 3 as well as python 2.

brew install python3 no longer works, so after some research, I ran brew upgrade python followed by brew install python2 to get back Python 2. However, I discovered that the python 3 installation process changed the default "python" to python 3, and that this broke all of my virtualenvs.

For example, if I execute workon test in the console, I get the errors

/usr/local/opt/python/bin/python3.6: Error while finding module
specification for 'virtualenvwrapper.hook_loader'
(ModuleNotFoundError: No module named 'virtualenvwrapper')
/usr/local/opt/python/bin/python3.6: Error while finding module
specification for 'virtualenvwrapper.hook_loader'
(ModuleNotFoundError: No module named 'virtualenvwrapper')
/usr/local/opt/python/bin/python3.6: Error while finding module
specification for 'virtualenvwrapper.hook_loader'
(ModuleNotFoundError: No module named 'virtualenvwrapper')
/usr/local/opt/python/bin/python3.6: Error while finding module
specification for 'virtualenvwrapper.hook_loader'
(ModuleNotFoundError: No module named 'virtualenvwrapper')

How can I unscrew-up my system? I need to be able to get back all my old work, even if it means obliterating python 3, although the ideal solution would be to find a way to have python 3 installed along side without interfering with the existing python 2 setup.

Best Answer

I eventually solved the issue by running

brew switch python 2.7.14
brew link --overwrite python

I'm not sure if that was the correct solution, but at least it seems to be working now.