Skip to content

Instantly share code, notes, and snippets.

@jjcall
Forked from larryisthere/gist:3291905
Created August 19, 2012 04:12
Show Gist options
  • Save jjcall/3391867 to your computer and use it in GitHub Desktop.
Save jjcall/3391867 to your computer and use it in GitHub Desktop.
How to setup Django/Postgresql on OS X Mountain Lion using Homebrew-based

Command Line Tools for Xcode

Command line tools comes bundle with Xcode prior to 4.3 version. After 4.3, you need to install a separated command line tools yourself.

First, go to this url and login using Apple Developer account (Free to register)

https://developer.apple.com/downloads/index.action

Look up the list and download the latest Command Line Tools for Xcode

Install Homebrew

Execute this command to install Homebrew

/usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

Or you've already have it, then execute this command to make sure it's updated

brew update

Homebrew website http://mxcl.github.com/homebrew/

Install Python

Latest version of brew will install pip as default

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

Add the following to .profile in your home folder

PATH=/usr/local/bin:/usr/local/share/python:$PATH
export PATH

Note: site-packages is in /usr/local/lib/python2.7/site-packages/

Install Virtualenv

pip install virtualenv virtualenvwrapper
mkdir ~/.virtualenvs

Add the following to .profile in your home folder

export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/share/python/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME

Create a new virtual environment by using

mkvirtualenv [your virtualenv name]

Note: --no-site-packages is deprecated since it is default, you won't need it any longer

Then start working on virtual environment by

workon [your virtualenv name]

Install Postgresql

PYTHON=/usr/local/bin/python  brew install postgresql
initdb -A trust /usr/local/var/postgres

Using trust, you will use your login name on Mac OSX to login to PostgreSQL

Load Postgresql automatically when login

cp /usr/local/Cellar/postgresql/9.1.3/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Note: pg_hba.conf is in /usr/local/var/postgres/

Install Psycopg2

pip install psycopg2

BUT if you want to use django-nose, you need to install psycopg2 version 2.4.1

pip install psycopg2==2.4.1

Install PIL

brew install PIL

Install Django

pip install django

This command could verify the installation

python -c "import django; print(django.get_version())"

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment