Installing Django, PostgreSQL 9, PostGIS in Arch Linux Django 04.07.2014

postgis-logo.png This post is small how-to install and setup bundle of GeoDjango, PostgreSQL 9, PostGIS in Arch Linux.

Python VirtualEnv

VirtualEnv is a Python tool used to create isolated environments for Python in which you can install packages without interfering with the other virtualenvs nor with the system Python's packages.

Also I'll use VirtualEnvWrapper for simplifying create, activate and remove virtualenvs.

yaourt -S python2 python2-pip python2-virtualenv python-virtualenvwrapper

VirtualEnvWrapper requires some initial setup

# vim ~/.zshrc

export WORKON_HOME=$HOME/.virtualenvs
source /usr/bin/

Re-open your console and create the WORKON_HOME folder


Create the virtualenv

mkvirtualenv -p /usr/bin/python2.7 myenv

Activate the virtualenv

workon myenv

Install some package inside the virtualenv

(myenv)$ pip install django pyproj

Install PostgreSQL, GDAL, GEOS, PostGIS

GDAL (Geospatial Data Abstraction Library) is a library for reading and writing raster geospatial data formats.
GEOS is a C++ library for performing geometric operations, and is the default internal geometry representation used by GeoDjango
PostGIS is a spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects allowing location queries to be run in SQL.

Install PostgreSQL, PostGIS

sudo pacman -Sy postgresql postgresql-libs postgis

Set password for postgres user

sudo passwd postgres

Init DB

su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'"

Run PostgreSQL

# in current session
systemctl start postgresql

# after reboot
systemctl enable postgresql

Install GDAL, GEOS

yaourt -S gdal geos

Setup and test PostGIS, GeoDjango

Test GEOS, GDAL, PyProj

# python shell


>>> from django.contrib.gis import gdal
>>> gdal.HAS_GDAL

>>> from django.contrib.gis import geos
>>> geos.geos_version()

>>> import pyproj
>>> pyproj.__version__
>>> pyproj.test()

Create DB (for PostgreSQL 9.1+)

# su - postgres

createdb dbname
psql dbname

> CREATE EXTENSION postgis_topology;

Configure db in and add django.contrib.gis to INSTALLED_APPS

    'default': {
         'ENGINE': 'django.contrib.gis.db.backends.postgis',
         'NAME': 'dbname',
         'USER': 'user',
         'PASSWORD': 'password',