Install pip and virtualenv, chicken and egg dilemma?

I have already used pip and virtualenv (and actually sometimes prefer a well-organized combination through the SVN repository, judicious use of svn: externals and dynamic sys.path).

But this time, for a new server installation, I would like to do everything right.

So, I go to the pip installation page and it says:

The recommended way to use pip is within virtualenv, since every virtualenv has pip installed automatically in it. This does not require root access or modifying your Python system. [...]

Then I go to the virtualenv page and offer:

You can install virtualenv using pip install virtualenv or the latest development using pip install virtualenv == dev. You can also use easy_install [...]

And the pip should replace easy_install, of course :)

Of course, they both explain all the alternative installation methods.

But ... what do you have to go first? And should I approve the system pip or not ?

I see the main reason to ponder, but there may be others.

  • Do I want to make life easier for all window users, or is it a server designed for a single user performing some services?

If I want everyone to have virtual env, I could just install the system package (for example, using ubuntu do sudo aptitude install python-pip , then use it to install virtualenv sudo pip install virtualenv ).

change another reason: virtualenvwrapper install instructions (but not docs ):

Note. To use virtualenvwrapper, you must install virtualenv separately.

not quite sure what it means "separately" (I never noticed).

Otherwise, which one should go first, and does it really matter or not?

Connected:

The next question (and answers) is the first of the following (in particular, see @elarson's answer), the second looks overly complex:

but I feel that it’s not possible to answer my question in full: on the whole system compared to local ones, but also need pip or virtualenv to go first (and why they send each of them to another to start with !! !)

+7
source share
3 answers

tl; dr The answer will first be VirtualEnv. You can have two of them for Python version 2.x and 3.x

[edit]

I really doubt that during installation (no installation, you just download and execute the script) VirtualEnv for the whole system or for each user. The whole point of using VirtualEnv is to create isolated sandboxes so that libraries from one project do not conflict with each other. For example, you can use the Python 2.x project using Beautiful-soup <4.x and A Python 3.x using Beautiful-soup Version 4.0 in two different virtual environments.

How you get a VirtualEnv script on your system doesn’t really matter, and since once you do this and pip will be autonomous in VirtualEnv, it just makes sense to get VirtualEnv first. Also, as soon as you connect to python, you will have many projects, and for each of them it is recommended to use a virtual environment, and then install dependencies via pip. You can later run pip freeze> requirements.txt and then pip install requirements.txt to simply replicate your exact libraries on two systems [say dev and production] etc ...

+6
source

Half one, six dozen the other. (Let it sink. Ha ha.)

But more seriously, do you honestly have several users on your system? Nowadays, even Linux hosts are usually intended for a single user, and where there are several user IDs, they are usually servers that execute several processes under different user IDs in quarantine. Given that making life easier for all users is not that important.

On the other hand, several services, each of which uses Python, may have conflicting requirements, are rare because it may be that it comes down to even the required version of pip . With this in mind, I would prefer a virtualenv global installation to make first-class Python quasi-installations.

But I would like to point out another idea: Buildout, http://www.buildout.org/

Buildout does the same thing as virtualenv, but using a completely different approach. You write a build configuration file ( buidout.cfg ) that lists your various eggs and how they will be connected, and specify the "build recipes" settings that configure specialized situations (for example, Django deployment, Buildbot server, Plone, Google application for applications etc.).

You then use your Python system to load the assembly, run it, and generate an isolated installation, such as virtualenv.

But the best part: repeatability. You can take the same buildout.cfg to another host and get the same setup. This is much harder to do with virtualenv!

+1
source

The final decision has not been decided yet, but what is happening right now is partly based on @nutjob's comments (no, I haven't switched to buildout yet, but I'll take some time for this later!)

I have a large, powerful server with a fairly large number of django applications. I mainly use gunicorn + supervisord.

These requirements are dictated by the following, but slightly different settings are likely to make them different.

  • I logically organized these applications in clusters based on code / function similarities; each cluster will most likely have the same version of the python shared libraries (pylibmc, pillow, etc.).
  • I create several users, one for each cluster
  • For each user, I install virtualenv (with the same name as the user of my choice), loading virtualenv.py and running python virtualenv.py VIRTUALENVNAME ; I do not install virtualenv wrapper
  • I am editing this .bashrc user so that virtualenv is immediately loaded.
  • I install generic packages using pip, but more specific packages are added directly through sys.path. This allows me to deploy even faster due to the project / version structure that contains all the necessary libraries. I find it more comprehensible, faster to deploy and easier to edit. The mileage for your individual cases may vary.

This means that each user has their own, unique virtualenv.

Should I start all over again, I will probably move on to creating or a similar solution (I am not a big fan of what happens when you mix the supervisor and virtualenv), but I am very pleased with that now ..

+1
source

All Articles