简体   繁体   中英

Error configuring django with python-mysql in Mac OS 10.6.6

My Setup:

  • Mac OS 10.6.6 - x86_64
  • MySQL 5.5.8
  • Python 2.7.1
  • Django 1.2.5
  • mysql-python installed via easy_install

My situation:

I've been struggling to get my setup to work. The problem is with the mysql-python interface. Originally, I was getting a similar problem (to the one I'm having with Django) doing an import statement in python:

import MySQLdb

But I read this question/solution that proved successful in fixing it. I installed django and it works great but it is having problems with the mysql interface. When I fire the Terminal and type:

>> python manage.py dbshell

the following error is generated:

Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/ init .py", line 438, in execute_manager utility.execute() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/ init .py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/ init .py", line 261, in fetch_command klass = load_command_class(app_name, subcommand) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/ init .py", line 67, in load_command_class module = import_module('%s.management.commands.%s' % (app_name, name)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_ module import (name) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/dbshell.py", line 4, in from django.db import connections, DEFAULT_DB_ALIAS File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/ init .py", line 77, in connection = connections[DEFAULT_DB_ALIAS] File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 92, in getitem backend = load_backend(db['ENGINE']) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 33, in load_backend return import_module('.base', backend_name) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module import (name) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 14, in raise I mproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/adogc45/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib Referenced from: /Users/adogc45/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so Reason: image not found

Now, I don't understand why importing the module in Python doesn't raise an error, but using the mysql interface in django does.

BTW, my settings.py looks like this:

DATABASES = {
'default': {
    'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.

Also, the image actually exits in .../MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp

So, I have NO idea about what's going on.

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

or:

pip install MySQL-python
pip install --upgrade MySQL-python

Helped me within a virtualenv

I had a similar problem, which I solved for the development program by including this line in my .bash_profile file (the magic file in my ~ directory which runs the shell): export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/ where the offending libmysqlclient.16.dylib is in that directory.

However, when I try to run this within Apache as a python wsgi module Apache cannot find the libmysqlclient.16.dylib no matter what I do. I have tried sys.path.append('/usr/local/mysql/lib') os.environ['DYLD_LIBRARY_PATH'] = '/usr/local/mysql/lib' no luck... seems Apache does not read this environment variable, nor does python in this context (where it is not reading my .bash_profile file)... help!!!

Try:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',

Instead of just mysql , if you're running Django 1.2.5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM