In this question on S/O:
Can existing virtualenv be upgraded gracefully?
The accepted answer says that you can:
use the Python 2.6 virtualenv to "revirtual" the existing directory
I cannot seem to find any details on how to "revirtual" an existing virtualenv. I know how to manually install python, but I am looking very specifically for the "python / virtualenv" way to upgrade python inside a specific virtualenv.
In my very specific situation, I have become an administrator in someone else' stead. The system python is 2.6.6, however the virtualenvs are all using 2.7.4 within the virtualenv path, which is something like:
/home/user_name/.virtualenvs/application_name/bin/python2.7
While there is no python 2.7.x in the system. I cannot find any evidence of python having been manually installed, and I cannot find any details online about using pip or using apt-get/yum or anything to install different versions of python within the virtualenv.
So, my very specific questions are:
Thanks, and please let me know if I can clarify my questions in any way!
-S
Usual caveat: make backup copies first. However, the structure created by virtualenv
is not that complex, so it should be possible to either find what you need or create a new one and migrate. The path with ~/.virtualenvs
in it means it was probably created with virtualenvwrapper so you could read up on that too.
virtualenv
makes copies of the executables in the bin
directory, which means they don't have to exist elsewhere. In the lib
and includes
directories, however, by default there will be symlinks to items from the "source" python (unless someone changed that setting). You could do a ls -l
in those directories and maybe you will find where python 2.7 is installed - or maybe some broken symlinks.
Under lib
should be one or more python-<version>
directories, with some symlinks (probably) to python standard library stuff and a site-packages
directory, which is where your installed packages are.
Now, upgrading. If you try to update the virtualenv "in-place" (i.e. you just run virtualenv --python==python<version> <existing-directory>
) then you'll probably run into two issues: (1) The bin/python
symlink will not be replaced unless you delete/move it, and (2) the directories under lib
are per python version, so if you don't use 2.7 then the site-packages
directory won't automatically carry over -- you'll have to reinstall packages, or go in and move it, which will probably work unless you have compiled binary extensions, or are migrating to 3.x, or something else weird happens.
An alternate, cleaner approach is to create a new, fresh virtualenv, and then reinstall the necessary packages. Find your own app's package(s) first and figure out if they have a setup.py
that works or are just code that's sitting in a directory. If they don't have setup.py
that correctly brings in all dependencies, then in your existing virtualenv folder you can run ./bin/pip freeze
to get a listing of installed packages. You can save this to a file and use pip install -r <filename>
on it later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With