Making iPython Virtualenv Aware

iPython is a great replacement for the standard Python shell, but, out of the box, it doesn’t play well with virtualenv.

This can be fixed with a couple of changes:

In the terminal generate an iPython default config file:

ipython profile create

Open the newly generated file:

vi ~/.ipython/profile_default/

Add the following code at the end of the file:

import site
from os import environ
from os.path import join
from sys import version_info

if 'VIRTUAL_ENV' in environ:
    virtual_env = join(environ.get('VIRTUAL_ENV'),
                       'python%d.%d' % version_info[:2],
    print 'VIRTUAL_ENV ->', virtual_env
    del virtual_env
del site, environ, join, version_info

And that’s it, iPython should now be virtualenv aware.

4 September, 2012 — 4 comments

Installing PIL on the Mac

The Python Imaging Library, PIL, is a very useful addition to your Python installation if you need to manipulate pictures. Django uses it to validate upload images for example.

On a Mac you do need to install libjpeg beforehand.

Install libjpeg:

  • Get the source:

  • Extract the archive.

  • Move inside the source directory and execute the following commands:

    cp /usr/share/libtool/config.sub .
    cp /usr/share/libtool/config.guess .
    ./configure --enable-shared
    sudo mkdir -p /usr/local/include
    sudo mkdir -p /usr/local/bin
    sudo mkdir -p /usr/local/lib
    sudo mkdir -p /usr/local/man/man1
    sudo make install

Install PIL:

  • Get PIL at:

  • Extract the archive.

  • Move inside the source directory

  • Change the following values in from the default None to:

    JPEG_ROOT = "/usr/local/include"
    ZLIB_ROOT = "/usr/local/include"
  • Check if everything is well configured:

    python build_ext -i
  • If no errors are found and the required libraries are installed (like JPEG support), install PIL:

    sudo python install

And that’s it, I’ve tried this on Mac OS Leopard, and it works fine, let me know how it went for you.

14 March, 2008 — 3 comments