django.core.exceptions.ImproperlyConfigured:错误加载My

2019-08-17 22:40发布

我下面Django的教程,很多人问这个问题,但我想我的情况有点特别,因为安装Python-MySQL时我尝试做蟒蛇manage.py执行syncdb我仍然得到这个错误后,

我在virtualenv中,因为我使用的MacPorts来管理我创造了我的virtualenv我的Python安装

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

这个使用MacPorts的我安装前的Django py27-django ,但我的创建后的virtualenv我认为它的更好,我安装Django到VIRTUALENV所以我用pip install django==1.5

据Django的教程中,我编辑我的settings.py文件,然后执行蟒蛇manage.py执行syncdb和我结束了以下错误:

[~/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重新安装,

(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

所以发生了什么吗? 貌似我有我需要与教程,但一些如何蟒蛇/ Django是抱怨没有MySQLdb的更进一步的一切。

Answer 1:

我libmysqlclient.18.dylib位于在/ usr /本地/ MySQL的/ lib目录/但我的系统是在/ usr / lib目录/寻找它。 我结束了创建libmysqlclient.18.dylib的符号链接在/ usr / lib目录中,解决了这一问题。

1)确保libmysqlclient.18.dylib中存在的/ usr /本地/ MySQL的/ lib目录/。

打开外壳。

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

您应该看到的文件:

libmysqlclient.18.dylib

如果没有,在系统中搜索文件的位置:

find / -name libmysqlclient.18.dylib

2.)创建libmysqlclient.18.dylib的在/ usr / lib中的符号链接

在你的shell中输入以下命令:

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

如果您libmysqlclient.18.dylib文件没有位于/ usr /本地/ MySQL的/ lib目录替换第一个路径与正确路径libmysqlclient.18.dylib。

希望帮助。



文章来源: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: