Fix broken Python virtualenv after an upgrade
It’s broken!
Python virtual environments are nice in many ways. However everytime I upgrade Python in Homebrew, I get something like this:
$ python
dyld: Library not loaded: @executable_path/../.Python
Referenced from: /Users/serge/.virtualenvs/gensys/bin/python
Reason: image not found
Trace/BPT trap: 5
Fortunately, it’s actually quite easy to fix!
Fixing virtualenv
- remove symbolic links
- re-create the virtual environment
In terms of commands:
$ cd myvirtualenv
$ find . -type l -print0 |xargs -0 rm -vf -- # Remove all symbolic links
$ virtualenv . # Don't forget custom arguments, like "-ppython2.7"
Done!