1

I installed mysql-python on 64bit snow leopard,and it's good under python IDE,but failed import in django. Anyone had meet similar question?

File "/Library/Python/2.6/site-packages/django/db/backends/mysql/base.py", line 14, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: 
Error loading MySQLdb module: dlopen(/Users/szanlin/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 
2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/szanlin/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
Reason: image not found
Ned Deily
  • 83,389
  • 16
  • 128
  • 151
szanlin
  • 11
  • 1
  • 3

2 Answers2

9

I had the same problem and I was able to find the answer here:

http://www.curlybrace.com/words/2011/01/25/mac-os-mysql-python-1-2-3-importerror-library-not-loaded-libmysqlclient-16-dylib/

Basically you need to add this line:

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

to your /etc/bashrc file.

Another page that was helpful can be found here:

http://programmingzen.com/2007/12/22/how-to-install-django-with-mysql-on-mac-os-x/

nates
  • 8,312
  • 5
  • 32
  • 28
  • 2
    Thanks! This was the last of about 20 problems between Python and MySQL on my machine :) – Andru Sep 12 '12 at 11:12
0

Just the clarify the above answer. Great answer and PowerAnimal is correct. If I could vote him up I would.

Please add the line:

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

to:

user/.bash_profile

This is a hidden file. You can view this file by using the following command in terminal.

defaults write com.apple.Finder AppleShowAllFiles YES

then:

killall Finder

When finished:

defaults write com.apple.Finder AppleShowAllFiles NO

then:

killall Finder

To check that Python is communicating with MySQL:

import MySQLdb

MySQLdb.apilevel

To check that Django is working:

import django

print django.VERSION

If no errors, you should be able to continue with your Django setup.

jason
  • 21
  • 3