Flickr Badge

Friday, September 02, 2011

pip re-installing wrong version of a package

I recently ran into a pip gotcha that left me scratching my head for hours.

When you install a package for the first time using pip, it will download the package into a build directory, unzip it there and install from there. Even if you uninstall it, the copy in the build directory remains intact. The next time you reinstall, pip checks if there is already a version in the build. If its there, then it directly installs that without downloading it again.

This is usually fine, unless you uninstalled in order to install a different version. In that case you might be mystified as to why the same old version is installed again.
pip install pycrypto==2.3

pip uninstall pycrypto
pip install pycrypto==2.0.1 # still installs pycrypto 2.3!!
The solution to this is to simply delete the package copy from the build directory.

If you are using virtualenv, then the build directory will be a top-level folder inside the virtualenv.

Thursday, September 01, 2011

Installing Python Imaging Library on Ubuntu

Continuing on setting up the VPS, its now time to install the Python Imaging Library. This is another major pain in the neck.

On Windows, PIL comes nicely bundled with everything. On Linux, it gets compiled, and the stupid part is that different bits of support get compiled in depending on what you have installed. PIL will silently skip components and say that the compile was successful. It's only when you run the application do you find out that some parts of PIL are not installed. Big, big, pain. If you are doing automated provisioning of machines, then you have to be careful that you have the right packages in place before you pip install PIL.

The two components that I am interested are PNG support and Truetype font support, because thats what we use for our app.

PNG Support

If you want PNG support, you need to have the zlib library installed.
sudo apt-get install zlib1g

sudo apt-get install zlib1g-dev
JPEG Support

JPEG requires libjpeg62
sudo apt-get install libjpeg62

sudo apt-get install libjpeg62-dev
TrueType Support

You'll need the libfreetype6 package installed
sudo apt-get install libfreetype6

sudo apt-get install libfreetype6-dev