Getting Django (or Python) to play nice with MySQL on Apple’s Mac OS X 10.6 Snow Leopard is really easy:
- Install MySQL. You can get the DMG from MySQL’s official download site (make sure you get the 64 bit version because Snow Leopard runs Python in 64bit)
- Type the following commands into terminal and you should be all set:
PATH=/usr/local/mysql/bin:$PATH
sudo easy_install mysql-python
Assuming that you already have Django setup properly and configured to run using MySQL, all you need to do is run manage.py runserver
If you run into errors similar to this, you are probably running MySQL in 32 bit, upgrading to 64bit of MySQL should fix this (this happened to me when I upgraded my OS from 10.5 Leopard to 10.6 Snow Leopard):
Unhandled exception in thread started by
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/django/core/management/commands/runserver.py", line 48, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.6/site-packages/django/core/management/validation.py", line 22, in get_validation_errors
from django.db import models, connection
File "/Library/Python/2.6/site-packages/django/db/__init__.py", line 41, in
backend = load_backend(settings.DATABASE_ENGINE)
File "/Library/Python/2.6/site-packages/django/db/__init__.py", line 17, in load_backend
return import_module('.base', 'django.db.backends.%s' % backend_name)
File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Python/2.6/site-packages/django/db/backends/mysql/base.py", line 13, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dynamic module does not define init function (init_mysql)
If, for some reason you prefer to stick with 32bit MySQL, you can also tell Python to run in 32bit mode by typing the following command into terminal (source):
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
To switch back to running Python in 64bit:
defaults write com.apple.versioner.python Prefer-32-Bit -bool no
Hope this bit of info helps some of you Django/MySQL developers out there
.
Leave a Comment