django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module:

限于喜欢 提交于 2019-12-21 02:44:10

问题


I am following the django tutorial, Many have asked the question but I think my situation is bit unique because after installing python-mysql I still get this error when I try to do python manage.py syncdb,

I am in a virtualenv since I use macports to manage my python installation I created my virtualenv

virtualenv code/vdjango --no-site-packages --python=/opt/local/bin/python

prior to this using macports I install django py27-django, but after creating my virtualenv I thought its better that I install django on to virtualenv so I used pip install django==1.5

According to django tutorial I edited my settings.py file and then execute the python manage.py syncdb and I end up with following error:

[~/code/vdjango/newsite]$python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
    utility.execute()
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
    from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/sql.py", line 9, in <module>
    from django.db import models
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/db/utils.py", line 27, in load_backend
    return import_module('.base', backend_name)
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/mac-pro/code/vdjango/lib/python2.7/site-packages/_mysql.so
  Reason: image not found

To confirm that I have install python-mysql package I ran the pip install again,

(vdjango)mac-pro@localhost:[~/code/vdjango/newsite]$pip install python-mysqldb
Downloading/unpacking python-mysqldb
  Could not find any downloads that satisfy the requirement python-mysqldb
No distributions at all found for python-mysqldb
Storing complete log in /Users/mac-pro/.pip/pip.log

So whats happening here? Looks like I have everything that I need to go further with the tutorial but some how python/django is complaining about not having mysqldb.


回答1:


My libmysqlclient.18.dylib was located in /usr/local/mysql/lib/ but my system was looking for it in /usr/lib/. I ended up creating a symbolic link of libmysqlclient.18.dylib in /usr/lib which fixed the problem.

1.) Make sure that libmysqlclient.18.dylib exists in /usr/local/mysql/lib/.

Open your shell.

sudo -s
ls /usr/local/mysql/lib/ | grep libmysqlclient.18.dylib

You should see the file:

libmysqlclient.18.dylib

If not, search your system for the location of the file:

find / -name libmysqlclient.18.dylib

2.) Create a symbolic link of libmysqlclient.18.dylib in /usr/lib

Enter the following command in your shell:

ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

If your libmysqlclient.18.dylib file wasn't located in /usr/local/mysql/lib replace the first path with the proper path to libmysqlclient.18.dylib.

Hopefully that helps.



来源:https://stackoverflow.com/questions/15593087/django-core-exceptions-improperlyconfigured-error-loading-mysqldb-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!