pip installing using wheels

Written by Miguel González on 2013-12-01

This is a quick recipe to improve dramatically the time needed to create Python virtual environments using the new wheel binary package format.

Pre requisites

First, make sure you have a pip version that supports wheel:

pip install --user --upgrade pip

Install wheel package:

pip install --user --upgrade wheel

I recommend to install packages in the user scheme and not system wide. This way, you don't need administrative rights, the system is not polluted with unneeded packages or broken dependencies and it's easier to reinstall if something goes wrong.

So summing up:

Making wheels

This step is common for user and virtualenv installed packages. We are creating a repository of wheel packages:

pip wheel --wheel-dir=$HOME/.wheelhouse psycopg2

It also builds its dependencies if any.

It is possible to use a requirements.txt file:

pip wheel --wheel-dir=$HOME/.wheelhouse -r requirements.txt

Notice that you can specify package version so a different wheel file will be generated:

$ ls .wheelhouse/psycopg2*
.wheelhouse/psycopg2-2.4.5-cp27-none-linux_x86_64.whl
.wheelhouse/psycopg2-2.5.1-cp27-none-linux_x86_64.whl

Installing from the local wheel repository

To use our brand new repository of wheel packages we must indicate pip to use it:

pip install --use-wheel --no-index --find-links=$HOME/.wheelhouse psycopg2

To install all requirements of a project:

pip install -r requirements.txt --use-wheel --no-index --find-links ~/.wheelhouse

Look at this screen capture, just 0.23 seconds:

(venv) $ time pip install --use-wheel --no-index --find-links=$HOME/.wheelhouse psycopg2
Ignoring indexes: https://pypi.python.org/simple/
Downloading/unpacking psycopg2
Installing collected packages: psycopg2
Successfully installed psycopg2
Cleaning up...
pip install --use-wheel --no-index --find-links=$HOME/.wheelhouse psycopg2
0.23s user 0.05s system 98% cpu 0.285 total

References

Links

Social