Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install pip and virtualenv, a chicken and the egg dilemma?

I've already been using pip and virtualenv (and actually sometimes still prefer a well organized combination through an SVN repository, wise usage of svn:externals, and dynamic sys.path).

But this time for a new server installation I'd like to do things in the right way.

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 in it automatically. This does not require root access or modify your system Python installation. [...]

Then I go to the virtualenv installation page and it suggests:

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

And pip is supposed to replace easy_install, of course :)

Granted, they both explain all alternative ways to install.

But... which one should go first? And should I favor systemwide pip or not?

I see a main reason to ponder over, but there might be others

  • do I want to facilitate life for all users of the box, or is this a server targeted to one single user running some services?

If I want everybody to have a virtual env available I might just install a system wide pip (eg. with ubuntu do sudo aptitude install python-pip then use it to install virtualenv sudo pip install virtualenv).

edit another reason to ponder over: virtualenvwrapper install instructions (but not the docs) say:

Note In order to use virtualenvwrapper you must install virtualenv separately.

not exactly sure what "separately" mean there (i never noticed).

Otherwise, which one should go first, and does it really make a difference or not?

Related:

The closest question (and answers) is the first of the following (in particular see @elarson answer), the second looks overly complicated:

  • What is the official "preferred" way to install pip and virtualenv systemwide?
  • What's the proper way to install pip, virtualenv, and distribute for Python?
  • Step by step setting up python with pip and virtualenv?
  • System PIP instead of virtualenv PIP by default?

but I feel it all fail at answering my question in full: systemwide vs. local, but also should pip or virtualenv go first (and why do they send each one to the other to start with!!!)

like image 218
Stefano Avatar asked May 09 '12 14:05

Stefano


People also ask

Why use virtualenv in Python?

virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects.

What is PIP in Virtualenv?

pip is a tool for installing packages from the Python Package Index. virtualenv is a tool for creating isolated Python environments containing their own copy of python , pip , and their own place to keep libraries installed from PyPI.

What is the best way to install PIP?

Step 1: Download the get-pip.py (https://bootstrap.pypa.io/get-pip.py) file and store it in the same directory as python is installed. Step 2: Change the current path of the directory in the command line to the path of the directory where the above file exists. Step 4: Now wait through the installation process.


1 Answers

tl;dr Answer would be VirtualEnv first. You can have two of them each for Python version 2.x and 3.x

[edit]

I am really doubtful if installing (there is no install, you merely download and execute a script) VirtualEnv system wide/per-user even matters. The whole point of Using VirtualEnv is to create isolated development sandboxes so that the libraries from one project doesn't conflict with each other. For example you can a Python 2.x project using Beautiful-soup Version < 4.x and A Python 3.x project Using Beautiful-soup Version 4.0 in two different Virtual Environments.

How you get VirtualEnv script on your system doesn't really matter, and since once you have it and pip is self contained within VirtualEnv, it just makes sense to get VirtualEnv first. Also once you are in with python, you would have many projects, and for each, the recommended way would be to have a Virtual Environment, and then install dependencies via pip. You can later do "pip freeze > requirements.txt" and then a "pip install requirements.txt" to simply replicate your exact libraries across two systems [say dev and production] and so on...

like image 55
subiet Avatar answered Oct 03 '22 08:10

subiet