django.core.exceptions.ImproperlyConfigured:加载MySQLdb模块时出错: [英] django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module:
问题描述
我正在学习django教程,很多人都问了这个问题,但是我认为我的情况有点特殊,因为在安装python-mysql之后,当我尝试执行python manage.py syncdb时,仍然会收到此错误,
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,
我在virtualenv中,因为我使用macports管理我的python安装,所以我创建了virtualenv
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
在使用macports之前,我先安装django py27-django
,但是在创建virtualenv之后,我认为最好将django安装到virtualenv上,所以我使用了pip install django==1.5
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
根据django教程,我编辑了settings.py文件,然后执行python manage.py syncdb,结果出现以下错误:
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
要确认我已安装python-mysql软件包,请再次运行pip安装,
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
那么这里发生了什么?看起来我已经具备了进一步学习本教程所需的一切,但是有些python/django如何抱怨没有mysqldb.
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.
推荐答案
我的libmysqlclient.18.dylib位于/usr/local/mysql/lib/中,但是我的系统正在/usr/lib/中寻找它.我最终在/usr/lib中创建了libmysqlclient.18.dylib的符号链接,从而解决了该问题.
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.
打开外壳.
sudo -s
ls /usr/local/mysql/lib/ | grep libmysqlclient.18.dylib
您应该看到该文件:
libmysqlclient.18.dylib
如果没有,请在系统中搜索文件的位置:
If not, search your system for the location of the file:
find / -name libmysqlclient.18.dylib
2.)在/usr/lib中创建libmysqlclient.18.dylib的符号链接
在您的shell中输入以下命令:
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
如果您的libmysqlclient.18.dylib文件不在/usr/local/mysql/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.
希望这会有所帮助.
这篇关于django.core.exceptions.ImproperlyConfigured:加载MySQLdb模块时出错:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!