Yet Another How to Install PIL on OS X in a virtualenv Recipe

The Python Library PIL can sometimes be challenging to install in OS X.

Installing PIL in a virtualenv can also add another layer of complexity to the task.

The need for this recipe arose from the fact that although our development and deployment environments at work are Linux, we frequently have the need to get a “local” environment running for our front-end developers and designers that are running OS X.

I’m posting it on the chance that it might be useful to others that need to get a workable virtualenv based environment on OS X setup that can be built to parallel their Linux environments and aren’t afraid to build some components from source.

Characteristics of this approach:

  • Doesn’t interfere with the Python build provided in OS X.
  • Doesn’t install software into system directories.
  • Doesn’t require “root” or “admin” level privileges.
  • Does allows for as many different builds/versions of Python as one needs.
  • Does require building Python and the relevant supporting libraries from source.

In this approach we’ll build a copy of Python and the necessary supporting libraries that we can install in a “local” directory of choice. In other words instead of installing into the /usr/local directory we’ll install into another specified directory (e.g. ~/local).

In order to build PIL with the necessary support for JPEG and FreeType we’ll also patch the setup.py file in the PIL source code to reference our new local installation of the libraries.

There are four (4) parameters in the bash script below that can be easily modified to meet one’s specific needs.

The script assumes that one will run it in the directory that one wants to use as the parent directory for the software to be built and installed (e.g. something like ~/ProjectName) .

The script will create a ./local , ./distfiles , ./src and a ./ve directory below the parent directory.

The example script below utilizes Python 2.7.1 but should work equally well with the appropriate changes for other Python versions.

Xcode must be installed.

#!/bin/bash
set -v
# ############################################################################
# script to build a python environment that
# includes PIL for OSX that can be easily used
# in a virtualenv
#############################################################################
# PARAMETER 1
# LOCAL_INSTALL_DIR sets the primary directory
# for the build to be installed into
#
LOCAL_INSTALL_DIR=`pwd`/local; export LOCAL_INSTALL_DIR
#
mkdir local
mkdir distfiles
mkdir src
mkdir ve
cd distfiles
curl -O http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
curl -O http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.6.1.tar.gz
curl -O http://www.ijg.org/files/jpegsrc.v8c.tar.gz
curl -O http://mirror.its.uidaho.edu/pub/savannah/freetype/freetype-2.4.4.tar.gz
curl -O http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
cd ..
cd src
tar xvfz ../distfiles/Python-2.7.1.tgz && \
tar xvfz ../distfiles/virtualenv-1.6.1.tar.gz && \
tar xvfz ../distfiles/jpegsrc.v8c.tar.gz && \
tar xvfz ../distfiles/freetype-2.4.4.tar.gz && \
tar xvfz ../distfiles/Imaging-1.1.7.tar.gz
# #################################################################################
#
cd ./jpeg-8c
./configure --prefix=$LOCAL_INSTALL_DIR && make && make install
cd ..
#
cd ./freetype-2.4.4/
./configure --prefix=$LOCAL_INSTALL_DIR && make && make install
cd ..
#
#############################################################################
#
LDFLAGS=-L$LOCAL_INSTALL_DIR/lib ; export LDFLAGS
#
cd Python-2.7.1/
./configure --prefix=$LOCAL_INSTALL_DIR && make && make altinstall
cd ..
#
PATH=$LOCAL_INSTALL_DIR/bin:$PATH; export PATH
#
cd virtualenv-1.6.1/
python2.7 setup.py install
cd ..
#
#############################################################################
#
LDFLAGS=-L$LOCAL_INSTALL_DIR/lib ; export LDFLAGS
#
cd Imaging-1.1.7/
cp setup.py.orig setup.py
cp setup.py setup.py.orig
sed "s@JPEG_ROOT = None\$@JPEG_ROOT = \'$LOCAL_INSTALL_DIR\'@" setup.py > setup.new
sed "s@FREETYPE_ROOT = None\$@FREETYPE_ROOT = \'$LOCAL_INSTALL_DIR\'@" setup.new > setup.new2
cp setup.new2 setup.py
python2.7 setup.py install
cd ..
cd ..
# #############################################################################
#
# PARAMETER 2
# LOCAL_VE_DIR sets the primary directory
# for the virtualenv to be installed into
#
# PARAMETER 3
# VIRTUALENV_NAME sets the name of the
# virtualenv to be created
#
# PARAMETER 4
# VIRTUALENV_DIR sets the primary directory
# for the individual virtualenvs to be installed into
#
LOCAL_VE_DIR=`pwd`/ve; export LOCAL_VE_DIR
VIRTUALENV_NAME=test_virtualenv1; export VIRTUALENV_NAME
VIRTUALENV_DIR=$LOCAL_VE_DIR/$VIRTUALENV_NAME; export VIRTUALENV_DIR
#
virtualenv $VIRTUALENV_DIR && cd $VIRTUALENV_DIR && source bin/activate && ./bin/easy_install pip
#

Hopefully this will be of some help to others.

Advertisements

pywebdev for Ubuntu v9.10 released

I’ve posted a release of the pywebdev Python Web Developer package for Ubuntu that has been updated for compatibility with the recently released Ubuntu v9.10 Karmic Koala .

Version 2.6 (updated to the recently released 2.6.4) is the default Python environment in Karmic.   For compatibility and flexibility pywebdev also includes complete environments for Python versions 2.4 and 2.5.

A small number of packages have changed since the v9.04 release:

Packages Added in v9.10
=========================
libevent-1.4-2
libevent-dev
vim-gnome
vim-gtk
vim-nox

Packages Removed in v9.10
=========================
linux-headers-server
libevent1
pypy
pypy-dev
python-xml
python-libgmail
zope3
zope-common
vim-python

John McCarthy Interview

Today I listened to Guy Steele interviewing John McCarthy on the history of Lisp.

For me the most most interesting part of the interview is the continued reference to how a proper representation of an abstract syntax was the most important aspect of a programming language. He discusses how having multiple concrete notations that map to a single abstract syntax may be desirable.

I also found interesting that at the time he considered dynamically typing (in Lisp) to be a bug and not a feature.

pywebdev for Ubuntu v9.04 released

I’ve posted a release of the pywebdev Python Web Developer package for Ubuntu update for the soon to be released v9.04-Jaunty Jackalope.

Version 2.6 (updated to the recently released 2.6.2) is the default Python environment in Ubuntu v9.04.   For compatibility and flexibility pywebdev also includes complete environments for Python versions 2.4 and 2.5.

A small number of packages have changed since the v8.10 release:

Packages Added in v9.04
=========================
python2.6
python2.6-dev
python2.6-examples
python2.6-minimal
python2.6-doc
python-cherrypy3
python-sphinx 
libapache2-mod-python-doc
pypy
pypy-dev
python-django-lint
python-git

Packages Removed in v9.04
=========================
python-urljr

An example of the Agile Cloud in action

An example of the Agile Cloud.

“You can build prototypes in the time it takes to have a meeting”
Simon Willison – Open Platform launch

This is phrase which sticks in my mind from Tuesday and I make no apologies for including it in 2 blog posts in a day. It has to be said that I don’t want ever to be in a 7 hour meeting (that was roughly how long ContentTagger took to build). However it’s still quite a quick turnaround and it got some extra niceness from a couple of “watercooler” moments (although one of them may have added on a couple of hours).

I definitely have attended meetings that have lasted at least seven hours.

The prototype was built using the default Google App Engine framework, Django templates and the Python client library for OpenPlatform.

A nice combination of Google App Engine, Python, and jQuery.

Review: Balsamiq Mockups

Balsamiq Logo

Overview

Balsamiq Mockups is a cross-platform (Windows, OS X, Linux) application that is great at creating quick and dirty, back of the napkin style (in a very good way) user interface wireframes.


Example Mock-Up

The mockups created by the application are essentially electronic sketches composed of both pre-built and user constructed user interface components.

Installation

The application is capable of running as a browser based application or a standalone desktop application.

The desktop application requires the Adobe Air runtime. Since I already had installed the Air runtime on the two platforms that I tested Balsamiq Mockups (Windows XP and Mac OS X), installation simply consisted of downloading the “MockupsForDesktop.air” file and double-clicking on the downloaded file (in my case version 1.5.33) to start the installation.

Features

Before running the application for the first time I quickly perused the available online help. The online help does a good job of covering the features and functions of the tool and because it is presented in a single web page it is easy to search and print if necessary .

Within 10 minutes of using Balsamiq I felt like I’d gotten the hang of the application and had produced my first complete mockup.

If you’ve used almost any kind of a drawing tool the features of Balsalmiq will be familiar and work as expected (e.g. guides, snap to grid, grouping elements, auto-alignment options, locking regions and layering).

The pre-installed library of UI components covers a range of common scenarios. Also there are more components that the Balsamiq community has developed available for download at www.mockupstogo.net. One suggestion I have for anyone trying the application is to use the “Quick Add” feature, once discovered, I found that I used is almost exclusively to locate the components that I wanted to add to my mockup.

One interesting and positive characteristic of the mockup files themselves is that they are straightforward XML files. This opens up the oppportunity to translate the mockups into other formats.

Example Mockup XML:

<mockup version="1.0" skin="sketch" measuredW="631" measuredH="585">
  <controls>
    <control controlID="0" controlTypeID="com.balsamiq.mockups::BrowserWindow" x="43" y="18" w="588" h="567" measuredW="450" measuredH="400" zOrder="0" locked="false" isInGroup="-1">
      <controlProperties>
        <text>A%20Web%20Page%0Ahttp%3A//</text>
      </controlProperties>
    </control>
    <control controlID="1" controlTypeID="com.balsamiq.mockups::TabBar" x="66" y="105" w="550" h="392" measuredW="256" measuredH="100" zOrder="1" locked="false" isInGroup="-1">
      <controlProperties>
        <text>One%2C%20Two%2C%20Three%2C%20Four</text>
      </controlProperties>
    </control>
    <control controlID="2" controlTypeID="com.balsamiq.mockups::VideoPlayer" x="119" y="172" w="458" h="204" measuredW="300" measuredH="200" zOrder="2" locked="false" isInGroup="-1"/>
  </controls>
</mockup>

Mockups can also be exported into nice looking PNG files for inclusion into the document of your choice.

One item that would be a good addition to the product would be to add the concept of a master template where a master template would include all of the design elements that are repeated between screens (or pages). An ability to define a master template for a mockup would greatly simplify changes across a related set of mockups. Another welcome addition would be some way to organize a set related mockups together. Perhaps this could be accomplished by defining a set of container elements in the mockup XML files.

The application also has support for functioning as a Jira plugin. At work we are moving to Jira so perhaps I’ll have the opportunity to test that aspect of the product next.

Conclusion

The application is an easy to learn and easy to use tool to create user interface “sketches” that convey the essential aspects of a design without the inclusion of unnecessary detail. This is a tool that is effective for hashing out the form and function of an interface without obsessing about the look and feel.

For large scale user interface prototyping the lack of a master template is potentially limiting. Because of the usefulness this kind of a feature I wouldn’t be surprised to find out that this feature is on the radar for a future release.

The bottom line is that I’m looking forward to using this tool on future projects.