What is the official "preferred" way to install pip and virtualenv systemwide?

118,309

Solution 1

If you can install the latest Python (2.7.9 and up) Pip is now bundled with it. See: https://docs.python.org/2.7//installing/index.html
If not :
Update (from the release notes):

Beginning with v1.5.1, pip does not require setuptools prior to running get-pip.py. Additionally, if setuptools (or distribute) is not already installed, get-pip.py will install setuptools for you.

I now run the regular:

curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python

Here are the official installation instructions: http://pip.readthedocs.org/en/latest/installing.html#install-pip

EDIT 25-Jul-2013:
Changed URL for setuptools install.

EDIT 10-Feb-2014:
Removed setuptools install (thanks @Ciantic)

EDIT 26-Jun-2014:
Updated URL again (thanks @LarsH)

EDIT 1-Mar-2015:
Pip is now bundled with Python

Solution 2

http://www.pip-installer.org/en/latest/installing.html is really the canonical answer to this question.

Specifically, the systemwide instructions are:

$ curl -O http://python-distribute.org/distribute_setup.py
$ python distribute_setup.py
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ python get-pip.py

The section quoted in the question is the virtualenv instructions rather than the systemwide ones. The easy_install instructions have been around for longer, but it isn't necessary to do it that way any more.

Solution 3

This answer comes from @webology on Twitter:

$ sudo apt-get install python-setuptools
$ sudo easy_install pip
$ sudo pip install --upgrade pip virtualenv virtualenvwrapper

My added notes:

  • On Mac/Windows (and Linux if the apt repo is outdated) you'd replace the first step with downloading setuptools from http://pypi.python.org/pypi/setuptools
  • On Windows you'd have to omit virtualenvwrapper from the last step and install it manually somehow. I don't know if there's a way to do this without Cygwin, but I hope so.

Solution 4

On Ubuntu 12.04 I've had good luck just using the package manager:

sudo apt-get install python-pip virtualenvwrapper

Solution 5

There is no preferred method - everything depends on your needs. Often you need to have different Python interpreters on the system for whatever reason. In this case you need to install the stuff individually for each interpreter. Apart from that: I prefer installing stuff myself instead of depending of pre-packaged stuff sometimes causing issues - but that's only one possible opionion.

Share:
118,309
coffee-grinder
Author by

coffee-grinder

I love StackOverflow!

Updated on July 14, 2020

Comments

  • coffee-grinder
    coffee-grinder almost 4 years

    Is it this, which people seem to recommend most often:

    $ sudo apt-get install python-setuptools
    $ sudo easy_install pip
    $ sudo pip install virtualenv
    

    Or this, which I got from http://www.pip-installer.org/en/latest/installing.html:

    $ curl -O https://github.com/pypa/virtualenv/raw/master/virtualenv.py
    $ python virtualenv.py my_new_env
    $ . my_new_env/bin/activate
    (my_new_env)$ pip install ...
    

    Or something entirely different?

  • coffee-grinder
    coffee-grinder about 13 years
    I'm asking about the preferred method specifically because I'm going to give these instructions to a class of 20 people and don't want to mislead them.
  • lambacck
    lambacck about 13 years
    Why are you bothering with python-setuptools and then distribute when you can go directly to distribute?
  • coffee-grinder
    coffee-grinder about 13 years
    @lambacck Could you please post what you are describing in a separate answer (even if it seems repetitive)?
  • coffee-grinder
    coffee-grinder about 13 years
    I know virtualenv comes with pip. Does pip come with virtualenv?
  • opricnik
    opricnik about 13 years
    No, you would just pip install virtualenv after that.
  • Carl Meyer
    Carl Meyer about 13 years
    If the condition is that you want system-wide installations of pip and virtualenv, this is what I generally do. The instructions from the pip docs that are given as the second alternative in the question are based on the premise that we're avoiding installing anything system-wide.
  • Carl Meyer
    Carl Meyer about 13 years
    Not to mention that on any recent Ubuntu (and Debian too? Not sure) the "python-setuptools" package actually IS distribute, so you may as well just skip the specific distribute step.
  • ncoghlan
    ncoghlan about 13 years
    Edited to clarify the difference between the systemwide instructions on that page and the virtualenv instructions that were quoted in the question.
  • lambacck
    lambacck about 13 years
    @coffee-grinder distribute is a fork of setuptools and therefor provides the same functionality (and more). Don't bother doing "apt-get install python-setuptools" unless python-setuptools IS distribute (as Carl indicates it might be) in which case skip steps 2 & 3.
  • JCotton
    JCotton about 11 years
    The packaged versions are far out of date. 12.04 provides python-pip 1.0-1build1 which was released in early 2011 and virtualenvwrapper 2.11.1-21 released January 2012. @Richard Jones' answer will get you the latest.
  • Tobu
    Tobu almost 11 years
    ✓ This is the best option if you don't want to rely on distribution packages.
  • Tal Weiss
    Tal Weiss almost 11 years
    Update: distribute does not work anymore for pip! See stackoverflow.com/a/17601159/78234
  • Steven Lu
    Steven Lu almost 11 years
    Where/how do you install setuptools-0.8? Looks like you are just grabbing ez_setup.py for a "lightweight version" of getting pip. I'd do the same but fear that it will break in the near future and I'll get stuck here again (like I always do)
  • Steven Lu
    Steven Lu almost 11 years
    Ah, looks like the instructions say to just do as you say here, it is sanctioned. Nevermind then.
  • Dennis
    Dennis over 10 years
    You can replace the first two commands with $ sudo apt-get install python-pip. Installing python-pip will also install python-setuptools.
  • Ciantic
    Ciantic over 10 years
    There is new (?) way to do this, this installs pip and setuptools automatically: wget --no-check-certificate https://raw.github.com/pypa/pip/master/contrib/get-pip.py and then python get-pip.py (may require sudo)
  • Neil Traft
    Neil Traft about 10 years
    Please note that the instructions on the linked page no longer match the instructions here. It is best to just visit the official page and do as they say (and why did anyone doubt them in the first place?!)
  • LarsH
    LarsH almost 10 years
    Now the URL for get-pip.py seems to have changed to https://bootstrap.pypa.io/get-pip.py. Probably better just to link to the official instructions.
  • Tal Weiss
    Tal Weiss almost 10 years
    Thanks @LarsH - edited my answer to reflect the change. Again.
  • LarsH
    LarsH almost 10 years
    P.S. Thanks for this answer - it helped me get pip installed.
  • orluke
    orluke over 9 years
    Any idea if it's possible to specify a specific version of pip by passing an argument to get-pip.py? Otherwise I'd just use the installed pip to install a specified version of pip, e.g. pip install -U pip==1.5.6
  • Tal Weiss
    Tal Weiss over 9 years
    @orluke Not sure why you would want to do this, but you can download pip from Github - here are the releases: github.com/pypa/pip/releases
  • cel
    cel over 9 years
    The approach described in this answer is outdated and does not seem to work anymore.
  • georgiecasey
    georgiecasey about 9 years
    debian version can be very old. check this answer for more info: unix.stackexchange.com/a/182467/17425