May 24, 2010
Simple Django Setup on Mac OS X
I’ve been getting into some JQuery lately and will be posting some slideshow code I’ve built. First, though – learning Python and Django has been something new to play with for the past few days. I ran into a problem getting Django to work with a database. The rest was pretty straight-forward, so if you’re looking to get Python updated and Django installed, check out this article: Install Django Official Release
MySQL vs SQLite3
I first tried MySQL because I am fairly familiar with it and it is pretty ubiquitous, but while MySQL appears simple to install at first, I ran into a few crazy errors:
- ERROR 1133 (42000): Can’t find any matching row in the user table
- django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
- error: command ‘gcc-4.2′ failed with exit status 1
The first was solved by connecting to MySQL as ‘root’@'localhost’ – ok, great.
The second appears that for some reason Python in OS X does not include the module for MySQL. – Uhhh, well, there was this resource to install it.
Finally, I had gcc (a C compiler) installed with XCode, it was version 4.2.1, but my only explanation was it wasn’t working because it was the 64bit version and I have a 32bit Macbook.
Ok, ok ok. That’s 4 hours down the drain.
Let’s try SQLite3: This article was helpful for this part.
- Open Terminal and see that SQLite3 comes installed
- $ sqlite3
- If yes, then (why did we mess with MySQL?)
- .exit (that’s dot exit to quit back to terminal)
- cd /your/django/project/ (or near it)
- $ sqlite3 mydatabase.db; (don’t forget the semi-colon)
- .databases (to verify creation and path)
- In your project’s settings.py, use ‘django.db.backends.sqlite3′ and ‘/your/django/project/mydatabase.db’
- Run python manage.py syncdb
- Success!
If you found this helpful, please visit a sponsor and get me some of that google money. Also, check out this book for learning Django – I’m using it now and can recommend it: Sams Teach Yourself Django in 24 Hours.
