Fixing virtualenv after Upgrading Your Distribution/Python

After you upgrade your python/distribution (specifically this happened to me after upgrading from Ubuntu 11.10 to 12.04), your existing virtualenv environments may stop working. This manifests itself by reporting that some modules are missing. For example when I tried to open a Django shell, it complained that urandom was missing from the os module. I guess almost any module will be broken.

Apparently, the solution is dead simple. Just re-create the virtualenv environment:

virtualenv /PATH/TO/EXISTING/ENVIRONMENT

or

virtualenv --system-site-packages /PATH/TO/EXISTING/ENVIRONMENT

(depending on how you created it in the same place). All the modules you’ve already installed should keep working as before (at least it was that way for me).

5 thoughts on “Fixing virtualenv after Upgrading Your Distribution/Python

  1. Guy Post author

    @Debraj: This means you should provide the full path to the directory where your virtualenv environment resides. For example /home/debraj/my_project.env

  2. Brandon

    I’m actually using a VENV folder from a git respository, so… I guess maybe my symlinks were broken by the 12.04 -> 14.04 upgrade. I got some errors running virtualenv /var/ww/project/venv (“unknown URL type” a few times, and something about pip failing) but it totally fixed my problem. Really happy this was the top result on Google — thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>