Skip to content

Instantly share code, notes, and snippets.

@brentcappello
Forked from panuta/gist:1852087
Created November 6, 2012 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentcappello/4025803 to your computer and use it in GitHub Desktop.
Save brentcappello/4025803 to your computer and use it in GitHub Desktop.
How to setup Django/Postgresql on OS X Mountain Lion using Homebrew

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

ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)

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

Install Python

brew install python

At this point, distribute and pip will also be installed by above command.

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 and Virtualenvwrapper

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]

or create a new virtualenv without any existing libraries

mkvirtualenv --no-site-packages [your virtualenv name]

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
initdb /usr/local/var/postgres -E utf8

Load Postgresql automatically when login (** DO NOT FORGET to change Postgresql version number below to match the current version of Postgres)

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

Login to Postgresql using your Mac OSX login name

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

Useful commands

Start Postgresql Server manually
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Stop Postgresql Server manually
pg_ctl -D /usr/local/var/postgres stop -s -m fast

Install Psycopg2

pip install psycopg2

Install PIL

brew install pil
pip install pil

Install Django

pip install django

Resources

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