Contact Us Now

Mac OS X Lion – Setting up Django, pip, virtualenv, and homebrew

We over here at TLS Web Solutions snagged ourselves yet another productive and time-saving piece of machinery — a MacBook Pro. While it ran smooth, we wanted to setup a Django dev enviroment pretty quickly and had a couple issues during that process.

Thankfully, Seanlin.me had just what the doctor order, a quick and easy Django dev setup guide for the Mac OS X.

Below are the steps are his setups that you can follow to get environment for Django up and running in no time.

The environment will contain –

  • Python 2.7
  • Django 1.3
  • Git
  • HomeBrew – a package manager for Mac OSX that allow you to install UNIX tools.
  • GCC Package Installer – XCode replacement
  • Pip – Package install for Python
  • PIL – Python Imaging Library
  • Virtualenv – virtual environment for Python

Installing HomeBrew

Copy and paste following codes inside the terminal.

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

Now you will have working installation of Homebrew. To test it out type

 brew 

in your terminal. If you see the list of example usage, your HomeBrew installation is a success.

UNIX Package Installer

If you have XCode installed on your system, then ignore this step. XCode is recommend for installing Python but not required. You can try to install Python without XCode by choosing an installer below.

Download and install –

For OS X 10.7 Lion: https://github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.7.pkg

For OS X 10.6 Snow Leopard: https://github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.6.pkg

https://developer.apple.com/xcode/

Installing Git

Just run following command in your terminal.

 brew install git 

Installing Python

Run the command

 brew install readline sqlite gdbm 

after completion, run following command

 brew install python --universal --framework 

Installing Pip

Pip allows you to manage and install Python packages. Run the following command in your terminal.

 easy_install pip 

Installing Virtualenv

Virtualenv allow you to have isolated Python environments for development. Run following command –

 pip install virtualenv 

Creating Virtualenv

To create the isolated environment to install and run Django, create a new folder for your project and browse into it,

 mkdir new_directory_name cd new_directory_name 

then run following command to start a new virtual environment –

 virtualenv environment_name --no-site-packages 

Change the “environment_name” to whatever name you want to set. Then run following two commands to activate virtualenv –

 source environment_name/bin/activate 

Again, replace the “environment_name” with the one you created above. Now you will have extra “(environment_name)” in your terminal.

Installing Django

Run following command to install Django –

 pip install django 

You now have a fully working environment for Django development. If you want MySQL support as well, run following two commands to install MySQL server and MySQL-python

 brew install mysql pip install http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz?use_mirror=cdnetworks-us-2 

Installing PIL

Just run following command to install PIL

 pip install PIL 

Starting Django Project

Browse to your project directory from command line and activate your virtualenv if it hasn’t

 source environment_name/bin/activate 

Remember to replace “environment_name” with the one you created. Once your virtualenv has been activated, run following command to start your Django project

 django-admin.py startproject project_name 

Replace the “project_name” with your own and you are good to start developing your Django apps.

THANKS AGAIN SEANLIN.ME! Click here to view the original instructions.

 



16 thoughts on “Mac OS X Lion – Setting up Django, pip, virtualenv, and homebrew

  1. Jean-Paul Rose on said:

    Thanks for the guide! Quick question though …. will this not interfere with the built in python that comes with OS X?

  2. Jean-Paul,

    Using the guide above, this will not affect your Mac’s version of Python. virtualenv installs a copy of Python for every local “environment” you create.

  3. Pingback: Ambiente de desenvolvimento Django no Mac OS X Lion | Blog do Jimmy

  4. Tracy Scott on said:

    New Homebrew install url…

    ruby -e “$(curl -fsSkL raw.github.com/mxcl/homebrew/go)”

  5. Pingback: Setting Up Eclipse with PyDev for Django « OhMyADragon

  6. Hi. Should I every time activate my virtualenv? When I want to work with some project? Sould I switch between virtualenv? For exsample to make “python manage.py runserver” in two differend virtualenva.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">