I recently installed a bunch of dotfiles on my Mac along with some other applications (I changed to iTerm instead of Terminal, and Sublime as my default text editor) but eve
If you using pipenv, just doing pipenv --rm
solves the problem.
I am sure I am late to the party but I want to say that the resolution of this problem is much simpler than discussed here.
You can easily regenerate the virtual environment without having to delete/edit anything. Assuming that your broken environment is called env_to_fix
you can just to the following:
mkvirtualenv env_to_fix
This will regenerate the links and fix the environment without the need to dump the current status somewhere and restore it.
This occurred when I updated to Mac OS X Mavericks from Snow Leopard. I had to re-install brew beforehand too. Hopefully you ran the freeze command for your project with pip.
To resolve, you have to update the paths that the virtual environment points to.
brew install python
pip install --upgrade virtualenvwrapper
rmvirtualenv old_project
mkvirtualenv new_project
workon new_project
pip install -r requirements.txt
This should leave the project as it was before.
Virtualenvs are broken. Sometimes simple way is to delete venv folders and recreate virutalenvs.
I found the solution to the problem here, so all credit goes to the author.
The gist is that when you create a virtualenv, many symlinks are created to the Homebrew installed Python.
Here is one example:
$ ls -la ~/.virtualenvs/my-virtual-env
...
lrwxr-xr-x 1 ryan staff 78 Jun 25 13:21 .Python -> /usr/local/Cellar/python/2.7.7/Frameworks/Python.framework/Versions/2.7/Python
...
When you upgrade Python using Homebrew and then run brew cleanup
, the symlinks in the virtualenv point to paths that no longer exist (because Homebrew deleted them).
The symlinks needs to point to the newly installed Python:
lrwxr-xr-x 1 ryan staff 78 Jun 25 13:21 .Python -> /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/Python
The solution is to remove the symlinks in the virtualenv and then recreate them:
find ~/.virtualenvs/my-virtual-env/ -type l -delete
virtualenv ~/.virtualenvs/my-virtual-env
It's probably best to check what links will be deleted first before deleting them:
find ~/.virtualenvs/my-virtual-env/ -type l
In my opinion, it's even better to only delete broken symlinks. You can do this using GNU find
:
gfind ~/.virtualenvs/my-virtual-env/ -type l -xtype l -delete
You can install GNU find
with Homebrew if you don't already have it:
brew install findutils
Notice that by default, GNU programs installed with Homebrew tend to be prefixed with the letter g
. This is to avoid shadowing the find
binary that ships with OS X.
The accepted answer does not work for me: the file $WORKON_HOME/*/bin/python2.7
is no longer a symlink, it is a full-fledged executable:
$ file $WORKON_HOME/*/bin/python2.7
/Users/sds/.virtualenvs/.../bin/python2.7: Mach-O 64-bit executable x86_64
...
The solution is, alas, to completely remove and re-create from scratch all the virtual environments.
For the reference:
deactivate
pip install --user virtualenv virtualenvwrapper
pip install --user --upgrade virtualenv virtualenvwrapper
for ve in $(lsvirtualenv -b); do
# assume that each VE is associated with a project
# and the project has the requirements.txt file
project=$(cat $WORKON_HOME/$ve/.project)
rmvirtualenv $ve
mkvirtualenv -a $project -r requirements.txt $ve
done