Homebrew broken link to Python in a virtualenv

Use something like this:

find <virtualenv> -type l -delete
virtualenv -p $(which python3) <virtualenv>

All of the symlinks are broken, so it's necessary to delete them. When you recreate the virtualenv it recreates the symlinks while keeping installed packages.

Note: Replace $(which python3) with location of whatever python version you want to use.


I'll put my comment as an answer, for clarity for future visitors with the same problem.

The related links you gave tell you exactly what's the problem: because virtualenv creates symbolic links to files, and homebrew replaces those files when upgrading with differently named files, you end up with broken links. Both related links give suggestions how to solve that: one to create a new virtualenv, the other to fix the broken links.

All in all though, when Python upgrades again in homebrew, you may end up with the same situation.

This was apparently realised by the virtualenv developers, and there is an option --always-copy to avoid problems like this:

$ virtualenv --help
Usage: virtualenv-3.4 [OPTIONS] DEST_DIR

Options:
  ...

  --always-copy         Always copy files rather than symlinking.

  ...

This should prevent problems when upgrading Python through Homebrew in the future. Though then, of course, your virtualenv will have an older version of Python. Which may at times be exactly what you want.