For the last few years, I have been using Ansible to configure my Macbook Pro. One of the things that my playbook does when it is run is update my homebrew installed applications. While this helps to ensure that I’m running the latest version of the apps that I install, it occasionally causes some issues with my Python virtualenvs. After an upgrade I may see something like this:
( fp-mbp: ~) % workon my-venv (my-venv) ( fp-mbp: ~) % python --version dyld: Library not loaded: /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Python Referenced from: /Users/mark.honomichl/.virtualenvs/my-venv/bin/python Reason: image not found zsh: abort python --version (my-venv) ( fp-mbp: ~) %
In this case, my virtualenv was created with python 3.7.4 and homebrew has updated my python to 3.7.6. Thankfully, the fix is rather easy. First step is to delete the stale links in your virtualenv.
deactivate my-venv cd ~/.virtualenvs/my-venv find . -type l -delete
Once you’ve removed the links, you can re-run the virtualenv wrapper command to recreate the symlinks.
With that, you virtual environment will be working again:
(my-venv) ( fp-mbp: ~/.virtualenvs/acg) % python --version Python 3.7.6 (my-venv) ( fp-mbp: ~/.virtualenvs/acg) %