Pip is a nice utility that allows you to easily install Python Packages into your working python path. I said working python path because pip is mainly used within a virtualenv.

Installing pip

#make sure you have all the dependencies required for pip to work.

$ sudo apt-get install python-pip python-dev build-essential

#upgrade pip to the latest version

$ sudo pip install --upgrade pip

Now that you have pip installed, I am sure you want to play with it. I will assume that you dont have a virtualenv activated.

#To install a package you simply run the following command. Note that you need to use "sudo" when you want to install in your main python path, but while working within a vertualenv you dont want to install using sudo.

$ sudo pip install bottle

#to install an specific version of a package

$ sudo pip install bottle==0.10.11

#to remove a package from your path

$ sudo pip uninstall bottle

#to upgrade an old package to the newest version

$ sudo pip install --upgrade bottle

#to install a git repository

$ sudo pip install git+git://github.com/ubuntuRocha/django-registration.git#egg=ubuntuRocha

With these five basic commands under your wing, you have become a pip ninja, congratulations.

Meet requirements.txt file!

The file that holds a list of all your dependencies is usually named requirements.txt. The advantage of having a file like this it is that you can install all your dependencies with one simple command, instead of having to install one by one.

This is what a requirements.txt file looks like:

Jinja2==2.6 Paste== bottle==0.10.11 distribute==0.6.15 gunicorn==0.14.6 wsgiref==0.1.2

In order to install all of those dependencies in one go you use the -r (recursive) option in conjunction with the pip install command. Make sure you list your dependencies in the correct order. If one dependency needs of another that has not been installed yet, pip will raise an Exception.

$ sudo pip install -r requirments.txt