Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Instructions on how to setup an OSX developer machine for (python/django) development

OSX Developer System installation

This guide assumes a fresh install of Mac OSX 10.6 Snow Leopard.


See for details.

  • Make sure X11 is installed (it's included in the default installation on Snow Leopard)
  • Install xcode4 - if you are downloading it from AppStore with Lion, remember to run the file "install Xcode", that will be in the Application folder, after the installation has completed
  • run this simple script: ruby -e "$(curl -fsSL"
  • edit PATH (e.g in ~/.bash_profile): export PATH=/usr/local/bin:$PATH (remember to logout and login again for the changes in .bash_profile to get picked up)

python and stuff

See for details.

the basics:

brew install python
/usr/local/share/python/easy_install pip
/usr/local/share/python/pip install --upgrade distribute

homebrew sets things up so that all packages installed via python install, easy_install or pip get their commands installed to /usr/local/share/python/ by default (see the above link for an explanation). So the first rule of business is to add that path to your PATH. Also if you want to use your homebrew python (and other homebrew stuff) by default, /usr/local/bin should be all the way at the front of your PATH.


export PATH


remember to open a new terminal or call source ~/.bash_profile in all of your open terminal windows to get PATH updated.

Before installing stuff with pip make sure you are using the correct version.:

pip --version

should return something like:

pip 1.0 from /usr/local/lib/python2.7/site-packages/pip-1.0-py2.7.egg (python 2.7)

PIL with pillow (recommended)

install some dependencies:

brew install jpeg lcms
pip install Pillow

PIL with patching

Since PIL is not packaged correctly, needs to be tweaked.

Use this version of pil ( and install it with FREETYPE_ROOT = ("/usr/x11/lib","/usr/x11/include",) in Then:

python build_ext -i
python install

PIL compatibility

Some python packages don't work when PIL is installed with the PIL prefix. Add a PIL.pth file in /usr/local/lib/python2.7/site-packages/PIL.pth containing the string PIL. Now both from PIL import Image and import Image will work.

This oneliner will do exactly that:

echo "PIL" > /usr/local/lib/python2.7/site-packages/PIL.pth


aggdraw provides much better anti-aliasing than PIL . And lots of other stuff.

use this version:

this needs mercurial to be installed (pip install mercurial)

mkdir ~/tmp
cd ~/tmp
hg clone
cd aggdraw-64bits
/usr/local/bin/python build_ext -i
/usr/local/bin/python install

Enabling freetype does not work for me. Please share if you find a way :-)



brew install mysql
# look at the instructions brew prints after installation. this is the short version:
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/mysql/5.5.12/com.mysql.mysqld.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
# set a root password
/usr/local/Cellar/mysql/5.5.12/bin/mysqladmin -u root password 'new-password'


brew install mysql-connector-c
pip install mysql-python



PYTHON=/usr/local/bin/python  brew install postgresql
# look at the instructions brew prints after installation. this is the short version:
initdb /usr/local/var/postgres
cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
launchctl load -w /usr/local/Cellar/postgresql/x.x.x/org.postgresql.postgres.plist
createuser # create the initial postgres user

python client bindings (does not work without the server):

pip install psycopg2

postgis / geodjango


brew install postgis # this will handle installing postgres, geos, proj4, and postgis
brew install gdal

creating a spatially-enabled database template:

createdb template_postgis # create a standard postgres db
createlang plpgsql template_postgis # enable the PL/pgSQL PostGIS functions
psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/postgis.sql
psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/spatial_ref_sys.sql

Creating a new database based on template_postgis:

createdb -T template_postgis [yourdatabase]

Alternatively it is possible to enable spatial functions on a existing databases by calling the above commands for creating template_postgis (except createdb, of course). Just use your existing database name instead of template_postgis

Other useful tools

git and hg:

brew install wget
brew install git hub
pip install mercurial

hub is a useful extension to make git github aware)

I had problems installing mercurial with pip on a 32bit MacBook Pro (Core Duo and less) because it failed to compile the 64bit version of the mercurial.base85 extension. So I downloaded the mercurial 1.8.2 package from pypi and removed -arch x86_64 near the end of and the ran python install and it worked fine.


install and make the command globally available:

brew install gettext
brew link gettext

more useful stuff

brew install ssh-copy-id
brew install vcprompt
pip install virtualenv
pip install virtualenvwrapper
brew install bash-completion
pip install ipython

the most useful package. this one is a must.:

brew install cowsay
cowsay You can now code python on OSX. Congratulations!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment