eat some code

Setup Django on Mac

Step by step guide to get Django working on MacOS Yosemite

February 2015 #Git  #Postgres  #LESS  #Flux  #Python  #Brew  #Django  #SASS  #PIP  #PyCharm  #MacOS  #venv 

I took some notes as I set-up Django and Python on a new Macbook running MacOS Yosemite (10.10). By following these steps, you'll have the best tools available - as far as I know - to code some Django apps.

For most required applications you can use PIP, MacPorts, Python sources, etc. As a result, you might end-up with a massive mess ! To avoid any issue, I'm using PIP & VirtualEnv so I can easily manage multiple Django projects. To do so, the easiest is to get started with Brew.

The libraries to install

A typical Django project requires:

  • a specific version of Django - and it will regularly change
  • many Django "plugins"
  • either SASS or LESS
  • PostgreSQL
  • and GIT of course

To cover these requirements and more, we are going to install:

  1. F.lux (for your eyes & brain ! )
  2. Brew (MacOs package manager)
  3. Git - via Brew (revision control)
  4. Python with PIP - via Brew (PIP is the python package manager)
  5. virtualenvwrapper - to make it easy to setup & use multiple projects
  6. LESS & SASS (CSS stuffs)
  7. PostgreSQL
  8. Pycharm - an awesome Python IDE

Even though you don't necessarily need all of these applications / libraries right now, you'll need them at some point.

1.F.lux - fixes blue light

This has nothing to do with Django but I consider this application to be a must have. It's a really quick download & install.

f.lux fixes this: it makes the color of your computer's display adapt to the time of day, warm at night and like sunlight during the day.

https://justgetflux.com/
Download F.lux

2.Brew - package manager

Open up your terminal (in the Finder it is under: Applications/Utilities/Terminal) and type:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then in ~/.profile add the path that will be used by applications installed via brew:

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

3.Git - revision control

In your terminal:

brew install git

4.Python with PIP

In your terminal (this will take a couple of minutes):

brew install python

You can now try to type pip in your terminal, it should work.

5.virtualenvwrapper

In your terminal (this will take a couple of minutes):

pip install virtualenvwrapper
mkdir -p ~/Envs
vi ~/.profile

In ~/.profile add:

export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh

For more information, see VirtualenvWrapper official documentation.

6.LESS & SASS

In your terminal:

brew install npm
npm install less -global
sudo gem install sass

7.PostgreSQL

For Postgres, I find it easier to use PostgresApp. First download it and then add it to your path so Django can find it.

Download PostgresApp

In ~/profile add:

export PATH=$PATH:/Applications/PostgreSQL.app/Contents/Versions/9.4/bin

Your ~/.profile should look like this:

export PATH=/usr/local/bin:/usr/local/sbin:$PATH
export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin

8.PyCharm

PyCharm is a fantastic IDE. You can try the professional edition for a month for free.

Download PyCharm

Et voilà !

You can finaly create a virtual environment and install Django. You can also use Git, Postgres, SASS & LESS.

mkvirtualenv myapp
pip install Django