Learn Django

Install the Database

The CRM Easy application requires a database to store data, such as user login credentials, account details, and contact information. This course will use the Postgresql open-source database. It is a very capable database, and is also compatible with the hosting provider, Heroku. Follow these instructions to install it.

Step 1: Mac Only - Install Xcode Command Line Tools

If you're running a Mac you'll need to install Xcode's command line tools. Follow these steps to do so.

  1. Open Apple's Developer site
  2. In the list of downloads, locate the Command Line Tools for your OS version and download the .dmg file
  3. Once the download completes, run the .dmg file and follow all steps to install the tools
  4. Restart any terminal you have running

Step 2: Install Postgres 9.3.5

Postgres 9.3.5 is recommended for this course as it is the latest version that is verified to work with the psycopg2 driver (installed later in this lesson).

As a side note, I was able to get the latest psycopg2 driver to work with Postgres 9.4. However, the author of the driver hasn't published a fully validated version yet compatible with 9.4 yet. If you do use Postgres 9.4 and have issues you may need to roll back to Postgres 9.3.5 just to be safe.

On a Mac

If you're using a Mac.

  1. Open PostgreSQL Download
  2. Follow the link to download Postgres 9.3.5. Be sure to download the right version for your OS type i.e. either 32-bit or 64-bit
  3. Once fully downloaded, open and run the .dmg file. Be sure to remember the password you choose during the installation

On Windows

If you're using Windows.

  1. Open PostgreSQL Download
  2. Follow the link to download Postgres 9.3.5. Be sure to download the right version for your OS type i.e. either 32-bit or 64-bit
  3. Once fully downloaded, open and run the .exe installation file and follow the prompts. Be sure to remember the password you choose during the installation

Step 3: Install Postgresql Adapter for Python

A software driver is required to give Python applications like Django the ability to use Postgres. For Postgres, that driver is called psycopq2. Install it by following these instructions.

On a Mac

Follow these steps to install the driver on a Mac. Make sure you're at a terminal and the virtual environment is activated.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# enter the entire command below
(venv)$ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install psycopg2

Downloading/unpacking psycopg2
  Downloading psycopg2-2.5.1.tar.gz (684kB): 684kB downloaded
  Running setup.py egg_info for package psycopg2

Installing collected packages: psycopg2
  Running setup.py install for psycopg2
    building 'psycopg2._psycopg' extension
...
Successfully installed psycopg2
Cleaning up...

On Windows

Follow these steps to install the driver on Windows.

  1. Open http://www.stickpeople.com/projects/python/win-psycopg/
  2. You will need to download the 2.7 version of the psycopg2 driver. Download either the 32 or 64 bit version depending on what your computer is running as
  3. Copy the downloaded file to C:\<path>\crmeasy\venv\
  4. Go to a command prompt and run:
1
2
3
4
5
# if you have a 32 bit machine
(venv) C:\<path>\crmeasy\venv\easy_install psycopg2-2.5.3.win32-py2.7-pg9.3.5-release.exe

# if a 64 bit machine
(venv) C:\<path>\crmeasy\venv\easy_install psycopg2-2.5.3.win-amd64-py2.7-pg9.3.5-release.exe

Step 4: Freeze Requirements

The pip utility is able to create a snapshot of all packages it has installed into the virtual environment. This is handy when you want to install the project on others servers, such as Heroku's. In this step you'll create a snapshot of the packages and save them to a file named requirements.txt. This file can then be used to install all the required packages on a new system.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# On a Mac: make sure you're in the crmeasy folder
$ pwd
/.../crmeasy

# On Windows: make sure you're in the crmeasy folder
C:\ echo %CD% 
C:\...\crmeasy

# create the requirements.txt file
(venv)$ pip freeze > requirements.txt

Step 5: Commit changes

Execute these commands to commit your changes.

1
2
3
4
5
# add files
(venv)$ git add .

# commit files
(venv)$ git commit -m "created django project, installed the postgres adapter, created requirements.txt"

Track your progress with a free account