Django/Mysql on Mac OS X Mountain Lion

Log-like errors and solutions while starting a project in Django with Mysql Database:

Downloading Mysql for mac from:

Install mysql-5.6.14-osx10.7-x86_64.pkg and the .prefs file for system preference control

Installing django :

sudo pip install django

Installing MySQL-python :

sudo pip install MySQL-Python



sh: mysql_config: command not found

Traceback (most recent call last):

File “<string>”, line 16, in <module>

File “/private/tmp/pip-build-root/MySQL-python/”, line 18, in <module>

metadata, options = get_config()

File “”, line 43, in get_config

libs = mysql_config(“libs_r”)

File “”, line 25, in mysql_config

raise EnvironmentError(“%s not found” % (mysql_config.path,))

EnvironmentError: mysql_config not found

Cleaning up…
Command python egg_info failed with error code 1 in /private/tmp/pip-build-root/MySQL-python
Storing complete log in /Users/sbeta/Library/Logs/pip.log


export PATH=$PATH:/usr/local/mysql/bin

add this line to .bashrc of your current user for permanent solution (nano ~/.bashrc)

testing if django is installed properly:

python -c "import django; print(django.get_version())"

creating the project for django: startproject mysite

try it out:

python runserver


Validating models…

0 errors found
November 26, 2013 – 01:03:07
Django version 1.6, using settings ‘InstaGate.settings’
Starting development server at
Quit the server with CONTROL-C.

Create your database with whatever tools you need, some prefer the mysql command line but I use Sequel Pro cause it’s easy to do and for my project I don’t need that much database administration. I may go with PhpMyAdmin later on.

adding the database detail to

‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’, # Add ‘postgresql_psycopg2’, ‘postgresql’, ‘mysql’, ‘sqlite3’ or ‘oracle’.
‘NAME’: ‘DBNAME’, # Or path to database file if using sqlite3.
‘USER’: ‘USER’, # Not used with sqlite3.
‘PASSWORD’: ‘PASSWORD’, # Not used with sqlite3.
‘HOST’: ”, # Set to empty string for localhost. Not used with sqlite3.
‘PORT’: ”, # Set to empty string for default. Not used with sqlite3.

(Also change the timezone to your timezone)

run the server one more time.


Traceback (most recent call last):
File “”, line 10, in <module>
File “/Library/Python/2.7/site-packages/django/core/management/”, line 399, in execute_from_command_line
File “/Library/Python/2.7/site-packages/django/core/management/”, line 392, in execute
File “/Library/Python/2.7/site-packages/django/core/management/”, line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File “/Library/Python/2.7/site-packages/django/core/management/”, line 280, in execute
File “/Library/Python/2.7/site-packages/django/utils/translation/”, line 130, in activate
return _trans.activate(language)
File “/Library/Python/2.7/site-packages/django/utils/translation/”, line 188, in activate
_active.value = translation(language)
File “/Library/Python/2.7/site-packages/django/utils/translation/”, line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File “/Library/Python/2.7/site-packages/django/utils/translation/”, line 159, in _fetch
app = import_module(appname)
File “/Library/Python/2.7/site-packages/django/utils/”, line 40, in import_module
File “/Library/Python/2.7/site-packages/django/contrib/admin/”, line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File “/Library/Python/2.7/site-packages/django/contrib/admin/”, line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File “/Library/Python/2.7/site-packages/django/contrib/admin/”, line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File “/Library/Python/2.7/site-packages/django/contrib/auth/”, line 17, in <module>
from django.contrib.auth.models import User
File “/Library/Python/2.7/site-packages/django/contrib/auth/”, line 48, in <module>
class Permission(models.Model):
File “/Library/Python/2.7/site-packages/django/db/models/”, line 96, in __new__
new_class.add_to_class(‘_meta’, Options(meta, **kwargs))
File “/Library/Python/2.7/site-packages/django/db/models/”, line 264, in add_to_class
value.contribute_to_class(cls, name)
File “/Library/Python/2.7/site-packages/django/db/models/”, line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File “/Library/Python/2.7/site-packages/django/db/”, line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File “/Library/Python/2.7/site-packages/django/db/”, line 198, in __getitem__
backend = load_backend(db[‘ENGINE’])
File “/Library/Python/2.7/site-packages/django/db/”, line 113, in load_backend
return import_module(‘%s.base’ % backend_name)
File “/Library/Python/2.7/site-packages/django/utils/”, line 40, in import_module
File “/Library/Python/2.7/site-packages/django/db/backends/mysql/”, line 17, in <module>
raise ImproperlyConfigured(“Error loading MySQLdb module: %s” % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Library/Python/2.7/site-packages/, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Python/2.7/site-packages/
Reason: image not found


Run and add this line to .bashrc:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

as far as the tuterial on django site goes now we should run

python migrate

However there is no migrate option. (In case you need south you have to install it now : pip install south)

instead of migrate you can run this:

python syncdb


Creating tables …
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session

You just installed Django’s auth system, which means you don’t have any superusers defined.
Would you like to create one now? (yes/no): no
Installing custom SQL …
Installing indexes …
Installed 0 object(s) from 0 fixture(s)

So now everything is set to start! you can start adding apps or projects in the same directory as now you have to create your database model and all that I may write in my next blog, if I don’t get lazy about writing it down. 😉

Let me know if this helped, it would be a great motivation for me to write more often!

%d bloggers like this: