Virtualenv uses nonexistent python interpreter

(James Harrison Fisher) #1

When I run virtualenv, I get this:

$ virtualenv
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory

This is due to virtualenv being a Python script using a nonexistent Python interpreter:

$ head -1 $(which virtualenv)

On my machine, /usr/local/opt/python is a symlink to a Python 3.6 directory:

$ ls -l /usr/local/opt/python
lrwxr-xr-x  1 jim  admin  24  2 Mar 13:45 /usr/local/opt/python -> ../Cellar/python/3.6.4_3

As expected, the Python 3.6 directory does not contain a bin/python2.7:

$ ls /usr/local/Cellar/python/3.6.4_3/bin/
2to3			idle			pip3			pydoc3.6		python3-config		python3.6m-config	wheel3
2to3-3.6		idle3			pip3.6			python			python3.6		pyvenv
easy_install		idle3.6			pydoc			python-config		python3.6-config	pyvenv-3.6
easy_install-3.6	pip			pydoc3			python3			python3.6m		wheel

virtualenv clearly expects /usr/local/opt/python to contain Python 2 material, but it only contains Python 3 material. Which is at fault?

(James Harrison Fisher) #2

Please disregard: I found that the blame for this lies with pip, not Homebrew. I have opened an issue regarding the broken behavior of pip install.

(James Harrison Fisher) #15

My emails show a conversation which doesn’t show up here; perhaps it was deleted. The conversation was inflammatory but contained some useful context. In particular:

The Homebrew 1.5.0 announcement announced the change which caused my Python interpreter to go away:

On 1st March 2018 the python formula will be upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link --force).

Apparently, this change was triggered by me running brew update.

(Mike McQuaid) #16

brew update will do brew migrate e.g. migrate formulae across renames. It will not upgrade formulae which is done by brew upgrade and, in this case, is what will handle the python binary change.

(Mike McQuaid) #17

Note: we are changing the behaviour of Python 2 and 3 tomorrow: Python and PEP 394

(James Harrison Fisher) #18

Great! Thanks for your hard work on this.

(I wasn’t aware of PEP 394. That sure is a strong reason to switch back.)