What is the "revirtual" in this answer?

In this question on S / O:

Is it possible to upgrade an existing virtualenv?

The accepted answer says you can:

use Python 2.6 virtual file to "revirtual" an existing directory

I cannot find any details on how to “upgrade” an existing virtualenv. I know how to manually install python, but I look very specifically at the "python / virtualenv" way of updating python inside a specific virtualenv.

In my specific situation, I became the administrator of someone else. System python is 2.6.6, however virtualenvs all use 2.7.4 inside the virtual path, something like:

/home/user_name/.virtualenvs/application_name/bin/python2.7 

While the system does not have python 2.7.x. I cannot find any evidence that python was installed manually, and I cannot find any details on the Internet about using pip or using apt-get / yum or anything else to install different versions of python in virtualenv.

So my most specific questions are:

  • How is one "revirtual" virtualenv?
  • How to update python inside virtualenv using "python"?
  • Are there alternative ways to control python versions in virtualenvs?

Thanks, and please let me know if I can clarify my questions anyway!

-S

+6
source share
1 answer

A common caveat: back up first. However, the structure created by virtualenv is not so complex, so it should be possible to either find what you need or create a new one and complete the migration. A path with ~/.virtualenvs in it means that it was probably created using virtualenvwrapper so you can read about it too.

virtualenv makes copies of executable files in the bin , which means that they should not exist elsewhere. However, in the lib and includes directories, by default there will be symbolic links to elements from the "source" python (unless someone has changed this setting). You can do ls -l in these directories, and you might find where python 2.7 is installed, or maybe some broken symbolic links.

There must be one or more python-<version> directories in lib , with some symbolic links (possibly) to the standard python library material and the site-packages directory where your installed packages are located.

Now, update. If you try to update virtualenv "in-place" (i.e. you just run virtualenv --python==python<version> <existing-directory> ), then you will probably encounter two problems: (1) The bin/python symlink bin/python will not be replaced if you do not delete / move it, and (2) the directories under lib on the same version of python, so if you are not using 2.7, then the site-packages directory will not be automatically transferred - you will have to reinstall packages or going in and moving this will probably work unless you compiled binary extensions or switched to 3.x, or something else Noe.

An alternative, cleaner approach is to create a new, fresh virtualenv, and then reinstall the necessary packages. First, find your own application package and find out if they have setup.py that works or is just code that is in the directory. If they do not have setup.py , which correctly introduces all the dependencies, then in your existing virtualenv folder you can run ./bin/pip freeze to get a list of installed packages. You can save this to a file and use pip install -r <filename> on it later.

+3
source

Source: https://habr.com/ru/post/973773/


All Articles