加载MySQLdb模块"错误#34;

时间:2015-10-29 05:08:07

标签: python mysql django

我安装了Django并在命令行上运行python manage.py runserver并继续收到此错误。我已经尝试了很多其他解决方案。例如,我已经完成pip install MySQL-python所以我已经拥有了MySQLdb,但无论如何我都会收到此错误:

   File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
  File "/Applications/anaconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
  File "/Applications/anaconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
  File "/Applications/anaconda/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
  File "/Applications/anaconda/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
  File "/Applications/anaconda/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
  File "/Applications/anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
  File "/Applications/anaconda/lib/python2.7/site-packages/django/contrib/auth/models.py", line 41, in <module>
class Permission(models.Model):
  File "/Applications/anaconda/lib/python2.7/site-packages/django/db/models/base.py", line 139, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
  File "/Applications/anaconda/lib/python2.7/site-packages/django/db/models/base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
  File "/Applications/anaconda/lib/python2.7/site-packages/django/db/models/options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/Applications/anaconda/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Applications/anaconda/lib/python2.7/site-packages/django/db/utils.py", line 240, in __getitem__
backend = load_backend(db['ENGINE'])
  File "/Applications/anaconda/lib/python2.7/site-packages/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
  File "/Applications/anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
 File "/Applications/anaconda/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Applications/anaconda/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Applications/anaconda/lib/python2.7/site-packages/_mysql.so
  Reason: image not found

2 个答案:

答案 0 :(得分:0)

MySQLdb使用系统上现有的mysql库,其中一个似乎缺失。

此处的关键错误是“未加载库:libssl.1.0.0.dylib”,您可能需要安装libssl,sudo apt-get install libssl1.0.0或mac brew install openssl

如果您不需要,可以在没有ssl支持的情况下构建。

答案 1 :(得分:0)

您使用的是Anaconda python发行版;因此,您需要运行conda install mysql-python下载并安装Anaconda的MySQL驱动程序。