Can existing virtualenv be upgraded gracefully?

You should create a new virtualenv using python2.6 and then, after activating the new env, use its python2.6 and its easy_install to install new versions of any site packages you need. Beware that the path name to the virtualenv is hardwired into various files within the environment, so, when you are ready to switch over to it, either change your startup scripts et al to refer to the new virualenv path or be very careful about copying it over to the old directory and modifying the path names inside it.


You can use the Python 2.6 virtualenv to "revirtual" the existing directory. You will have to reinstall all the modules you installed though. I often have a virtual directory for developing a module, and virtualenv the same directory with many versions of Python, and it works just fine. :)


In Python 3.3+ venv supports --upgrade flag

  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.

Usage:

python -m venv --upgrade YOUR_VENV_DIRECTORY

I just upgraded my venv from Python 3.7.x to 3.8 on several projects without any issue.