UPDATE 1/14/13: A few small corrections. See Jonathan’s comment below if you’re having issues installing mysqldb
A few years ago, I posted instructions on installing Django on Snow Leopard. Since then, things happen gotten a lot easier. At that time, there was a weird shift going on with 64-bit computing that made it difficult to know what versions of various software to install. Well, it’s a few years past that, and package installers have become much easier to use as well. So, if you’re looking to do a fresh Django install on your computer, take a look:
1. Install MySQL
Download MySQL from http://dev.mysql.com/downloads/mysql/. Specifically, you want the “Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive” version. Install mysql*.pkg as given. If you would like, you can also install the startup item (if you want MySQL to start automatically) and the preference pane so that MySQL can be started from System Preferences.
For some convenience, you can also add mysql to your path to invoke it in Terminal directly. To do this, open ~/.bash_profile with your favorite editor, and add
to it. You should also set your root password for MySQL using
/usr/local/mysql/bin/mysqladmin -u root password YOUR_PASSWORD
- http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion (also has handy instructions for setting up Apache if you need to serve content as well)
2. Install libjpeg
Feel free to skip this if you don’t need the Python Imaging Library, but if you do, homebrew is the easiest way to get it and many other packages that you deserve as a UNIX user. Long ago, I used fink, and it was an awful experience. I hope they’ve improved it since, but homebrew was so painless.
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
brew install libjpeg
3. Install virtualenv (recommended)
I hadn’t used virtualenv before doing this setup, but it’s great. In short, it creates a virtual environment to setup python packages. Even though it’s easy to install packages otherwise, it does become a mess if different applications have different dependencies or if you need to swap python versions. This does away with all of that.
sudo easy_install virtualenv
sudo easy_install virtualenvwrapper
Then start from line 2 of https://gist.github.com/1852087 to get your virtualenv setup.
- https://gist.github.com/1852087 (if you’re using PostgreSQL, I recommend these installation instructions over mine
4. Install the python packages
If you didn’t install virtualenv, you’ll need to install pip (sudo easy_install pip) since pip otherwise is packaged with virtualenv. You will also need to sudo the next steps.
I recommend that you use a requirements file to setup your packages. It probably isn’t a big deal if you’re working on your own project, but it’s immensely handy as soon as someone else needs to setup the same environment as you. To do that, create a requirements.txt with contents similar to
pillow is optional depending on if you want PIL, and so is South. If you have your own favorite way of doing schema migrations, feel free to substitute. If not (or if you don’t know what South is for*), I recommend South. After you have that setup, just run
pip install -r /PATH/TO/requirements.txt
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
I don’t exactly know what the circumstances are for requiring the second line, but I needed it, so I’m going to assume you will too.
And that’s it! Now, you can fire off your Django project from within your virtual environment for local development. If you mine through some of the other links above, you will find a lot of other really good instructions for setting things up. Presumably, you can also google things as necessary.
Let me know in the comments if you run into any problems, if I missed anything, or if you have any proposed enhancements to this process. Also, let me know if I can do any other advocacy on the part of Django. I have had largely good experiences with it for building websites.
* one thing that Django doesn’t address well is database migrations. When you setup your models initially, Django will create db tables for the fields you specify. As fields change, however, Django doesn’t deal with changing the db tables. A tool like South will analyze your models and create migrations for you to run and modify the db schema