
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.
- 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.
This setup guide was a VERY useful for me. Thanks so much for taking the time to write it.
I found it incredibly useful when I found it too. Not a problem.
The url for brew is old. To install it, paste this code into terminal:
/usr/bin/ruby -e “$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)”
Thanks, Alex. I’ll update it right away.
Thanks for the guide! Quick question though …. will this not interfere with the built in python that comes with OS X?
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.
Oh ok thanks … I’ll be giving it a try
Pingback: Ambiente de desenvolvimento Django no Mac OS X Lion | Blog do Jimmy
Great stuff – this made my install very simple. Thanks!
Thanks this was very helpful. I’ve tried so many times to get my environment setup, this worked like a charm. Thanks!
Even Alex updated link returns an error 404. Is there a new link that is working?
just a feedback: these steps woks in moutain lion 10.8.2
New Homebrew install url…
ruby -e “$(curl -fsSkL raw.github.com/mxcl/homebrew/go)”
fyi, an existing ~/.pydistutils.cfg can trip up brew python install…
brew python install failed with
ImportError: No module named time
According to this…
https://github.com/mxcl/homebrew/issues/11594
fix is to remove ~/.pydistutils.cfg…
rm ~/.pydistutils.cfg
Pingback: Setting Up Eclipse with PyDev for Django « OhMyADragon
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.