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.


Greg Ball said...

I've just struck the same problem. This is really odd behavior, seems like a bug to me. Because I found your post, I haven't wasted much time, so thanks!

Siddhi said...

Glad it helped :)

Christopher Bare said...

This stack overflow post covers the same issue:

Asking pip to be really really verbose might get it to tell you where that cached copy of the library is.

pip install -v -v -v