Python Package Manager: PIP

The Python package manager pip is a tool to manage the installed site packages. With pip, we don't have to be worried about the package dependencies anymore. pip will download the required packages from Python Package Index automatically.

Install Packages

To download and install the packages from Python Package Index:

$ pip install package1 package2 package3

For example, we can install Django and its dependencies with:

$ pip install django

In some scenario, we have to install the package with specific version. We can achieve this with the version qualifier:

$ pip install 'django==1.5'
$ pip install 'django>=1.7'

We can also write a requirements.txt with various packages, for example:

django-sendfile
django>=1.7

And then install packages with:

$ pip install -r requirements.txt

Some projects have extra requirements. To install those requirements, we have to specify the name in the brackets, for example:

$ pip install waliki[all]

Install Packages for Development

To install the lastest still-in-development packages, which has not been released to Python Package Index, we can install them by specifying the tarball URLs.

For example, we can install the latest Django packages from their master branch with:

$ pip install https://github.com/django/django/tarball/master

We can also install the package from the local file system with the file:// protocol:

$ pip install "file:///path/to/the/package#egg=name"

For example, to install latest Waliki from Git repository:

$ git clone https://github.com/mgaitan/waliki
$ cd waliki
$ pip install "file://$(pwd)#egg=waliki[all]"

Sometimes, it is more convenient use the Python files in-place, so that we don't have to reinstall the package after changing any files. We can achieve this with -e option:

$ pip install -e path/to/the/package

For example:

$ git clone https://github.com/mgaitan/waliki
$ cd waliki
$ pip install -e .[all]

With pip install -e, we can save a lot of development time!

Uninstall Packages

Finally, we can remove the package with the pip uninstall command:

$ pip uninstall package-name