Django Aware

« | Home | »

Installing Django And MySQL On MacBook Air Or OS X

By Paul Kenjora | April 15, 2008

I recently got a MacBook Air and decided to run a native Django install with MySQL. I set things up the wrong way first, then I went through and got things running the right way. OS X takes a little getting used to as it works a bit differently than typical Unix setups. Getting Django running on a MacBook Air with OS X as follows:

  1. Make sure you do EVERYTHING on the command line as root. Use the command "su -". If you do not then everything will install into the "/opt/local…" path vs. the "/Library…" path. Now your libraries for MySQL and Python and Django will be scattered and it will be tough to get things running right. ust use "su -" and save yourself alot of trouble.
  2. Install MySQL as your database. My MacBook Air has the intel chipset with OS X Version 10.5.2. So I downloaded: Mac OS X 10.5 (x86). This step is not done from the command line, simply open the downloaded file, and proceed through the steps. When you’re done you can remove all the associated icons and mounted installs from your Desktop.
  3. Install the Python MySQL libraries in the form of MySQLdb 1.2.2 from the command line. Download it from: mysql-python 1.2.2. You will be redirected to the download page from the previous link where you should pick MySQL-python-1.2.2.tar.gz. Save the file to your drive. Then issue the following commands on it.
  4. When you run the commands above there will be an error with "python setup.py install", no worries its easy to fix:
  5. According to Michal Kox you will need to remove the lines listed below from the _mysql.c file:
  6. Now run "python setup.py install" and everything will finish OK, ignore the warnings. Everything is now ready for the Django install. Download Django-0.96.1.tar.gz. Follow the instructions on the download page. Again make sure you are executing everything as root "su -". The Django page really does the best job at explaining the install steps for this part.
  7. One Django is installed, start the MySQL server:
  8. Now you’re ready to write your Django applications, a great starting point is the tutorial.

So far the combination of Django and OS X on a MacBook Air has been unbeatable. I can develop the back end from the command line while getting all the benefits of a GUI for front end graphics. Any Django developer serious about getting the most out of a system with the least effort should invest in a Mac ASAP.

Topics: Environment Setup, Tutorial | Comments

  • For those of you having issues with the setup steps:

    The problem:

    EnvironmentError: mysql_config not found

    The fix:

    Just add the /path/to/mysql/bin directory to your $PATH

    The mysql/bin directory has a binary called mysql_config. The setup_posix.py checks for this using..
    (in the get_config() function called from setup.py)
    <snip>
    from setup_common import get_metadata_and_options, enabled, create_release_file
    metadata, options = get_metadata_and_options()

    if 'mysql_config' in options:
    mysql_config.path = options['mysql_config']
    </snip>

    Basically if it can't find the program binary called mysql_config, then it fails.
  • Howard
    "Mac OS X 10.5 (x86)" is not available for download on the MySQL link you gave us. It only goes up to 10.4
  • Thomas
    Your new mac comes with Python 2.5.1 and sqlite3.4.0; Django runs happily in that environment!

    If you would like to compile software on you mac, macports or fink will save you a *lot* of time.

    Xcode is on the (Leopard) DVD btw. sot there's no need downloading that.

    Thomas
  • Jeff,

    I don't know any feature that Textmate can do and Gedit not... but in the end, VIM is the best overall. And you just CAN'T tell me that VIM works better on a Mac.
  • Oh right I did forget I spent last week downloading XCode. I'll add that.
  • NiKo
    You should say that XCode tools should be installed to compile Python-MySQL ;)
  • All your test editors are belong to VIM.

    Now overall if you've been on the fence about getting a Mac laptop as your next development machine, do not hesitate. Talk to me 3 months ago and I would have laughed at the idea, coming from someone whose done Fedora, Ubuntu, VMWare, dedicated linux box, and even XP. Django + Mac Laptop + Mysql really is the development environment for perfectionists with deadlines.
  • Jeff
    Igor,

    I agree that the Debian Package Management System is the best. Its why I used Debian for years and now use Ubuntu on my servers and Linux desktops. But MacPorts is based off of FreeBSD's port system and is pretty good.

    Please don't compare gEdit to Textmate. Its not even close. Textmate is one of the main reasons I use a Mac for my development.
  • Please, don't be a fanboy, you just remember me DHH...

    The fact is that Django is way more easier to install and develop on Linux on a APT based distro like Ubuntu.

    Textmate can't bet my Gedit.
  • Jeff
    Where's the instructions for Django? This looks like a tutorial for installing MySQL. I'm running Django on my MacBook Pro and it was pretty simple. I use the default Python for starters. Then check out the Django trunk and install it to /opt/django-source. Link the django subdirectory to /Library/Python/2.5/site-packages and you're done.

    I don't use MySQL. I like PostgreSQL. But there is an easier way for you to install MySQL. Use MacPorts. Install MacPorts and then you can install MySQL like this: sudo port install mysql-server
  • casseen
    I had to work a lot with macs recently and I am not impressed. Not impressed at all. I will give osx another chance if apple starts selling it without their overpriced hardware.
  • must feel good to code django in the air
blog comments powered by Disqus