简体   繁体   English

在OS X上使用Django中的MySQL时找不到libmysqlclient.18.dylib映像

[英]libmysqlclient.18.dylib image not found when using MySQL from Django on OS X

I'm starting down the path of learning Python/Django and have hit my first snag. 我开始学习Python / Django的路径,并且遇到了我的第一个障碍。 When attempting to set my database in settings.py , the internal server fails with: 尝试在settings.pysettings.py数据库时,内部服务器失败并显示:

File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/rob/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/rob/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
Reason: image not found

There are a lot of solutions that I've found, mostly involving the explicit definition of my DYLD_LIBRARY_PATH value, but that doesn't work for me. 我找到了很多解决方案,主要涉及我的DYLD_LIBRARY_PATH值的明确定义,但这对我不起作用。 MysQL-Python is installed (v1.2.3). 安装了MysQL-Python (v1.2.3)。

Any idea what I might need to do to push through this? 知道我可能需要做些什么才能完成这项工作?

Thanks. 谢谢。

UPDATE UPDATE

DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.mysql',  # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'django_tutorial',                      # Or path to database file if using sqlite3.
    'USER': 'root',                      # Not used with sqlite3.
    'PASSWORD': '',                  # Not used with sqlite3.
    'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
  }
}

From your comments, it appears that the libmysqlclient dylib was installed with a non-absolute library name path. 从您的注释中可以看出, libmysqlclient dylib安装时带有非绝对库名称路径。 That's contrary to standard practice on OS X which is different from most other Unix-y systems in this respect. 这与OS X上的标准做法相反,OS X在这方面与大多数其他Unix-y系统不同。 You should be able to permanently fix the problem (at least until your next upgrade) by modifying the path in the .so file by using install_name_tool or you can make it work by ensuring your Django instance is running with the following environment variable defined: 您应该能够通过使用install_name_tool修改.so文件中的路径来永久修复问题(至少在下次升级之前),或者通过确保Django实例运行并定义了以下环境变量来使其工作:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib

You also might be able to get it to work by creating a symlink in /usr/local/lib to the dylib in /usr/local/mysql/lib since /usr/local/lib is on the default dynamic load search path, so (untested!) something like: 你也可以通过在/usr/local/lib创建一个符号链接到/usr/local/mysql/lib的dylib,因为/usr/local/lib在默认的动态加载搜索路径上,所以你也可以使它工作。 (未经测试!)类似于:

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

A better long-term solution is to not use a broken MySQL client installation as suggested in Python import MySQLdb error - Mac 10.6 . 一个更好的长期解决方案是不使用Python导入MySQLdb错误 - Mac 10.6中建议的破坏的MySQL客户端安装。

Using a homebrew installation of mysql , this worked for me: 使用自制mysql安装,这对我有用

$ mdfind libmysqlclient
/usr/local/Cellar/mysql/5.7.9/lib/libmysqlclient.20.dylib
/usr/local/Cellar/mysql/5.7.9/lib/libmysqlclient.a
/usr/local/Cellar/mysql/5.6.27/lib/libmysqlclient.18.dylib
/usr/local/Cellar/mysql/5.6.27/lib/libmysqlclient.a
/usr/local/Cellar/mysql/5.6.26/lib/libmysqlclient.18.dylib
/usr/local/Cellar/mysql/5.6.26/lib/libmysqlclient.a

$ sudo ln -s /usr/local/Cellar/mysql/5.6.27/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib

You probably have upgraded mysql recently. 您最近可能已经升级了mysql。 I got this issue when I upgraded MySql from 5.6 to 5.7 with brew. 当我用Brew将MySql从5.6升级到5.7时,我遇到了这个问题。 This definitely broke some libs, but relinking mysql back to 5.6 fixed the issue. 这肯定打破了一些libs,但是将mysql重新连接回5.6修复了这个问题。 So first see what mysql version you had previously with: brew info mysql and after switch back to that version using brew switch mysql 5.6.22 command for example. 首先看看你之前使用过的mysql版本: brew info mysql ,然后使用brew switch mysql 5.6.22命令切换回该版本。

Make sure you have not just MySql-Python, but the actual MySql. 确保你不仅仅是MySql-Python,而是实际的MySql。 MySQL-python is trying to load the mysql library, which should be somewhere like /usr/local/mysql-VERSION/lib. MySQL-python正在尝试加载mysql库,它应该在/ usr / local / mysql-VERSION / lib之类的地方。

Try running 试试跑步

mdfind libmysqlclient

on the command line. 在命令行上。 Scan through those results and if you don't see the file it's missing (libmysqlclient.18.dylib) then you probably don't have mysql installed properly. 扫描这些结果,如果你没有看到它丢失的文件(libmysqlclient.18.dylib),那么你可能没有正确安装mysql。

I don't have enough reputation to comment on Ned Deily's answer above :), but the environment variable method worked for me, after fixing the typo; 我没有足够的声誉来评论Ned Deily上面的答案:),但环境变量方法在修正错字之后对我有用; it should be: 它应该是:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib

If you go that route I would suggest two things; 如果你走那条路,我会建议两件事; make sure you don't bash any other DYLD_LIBRARY_PATH settings by using 确保您不使用任何其他DYLD_LIBRARY_PATH设置

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

and put it in your .bashrc file so you don't have to remember to set it in each terminal session. 并将其放在.bashrc文件中,这样您就不必记住在每个终端会话中设置它。

The benefit to this method over the symlink option is that it will allow all the mysql dylib files to be found, not just the one(s) you specifically symlink. 通过符号链接选项对此方法的好处是它将允许找到所有mysql dylib文件,而不仅仅是您特定符号链接的文件。

Can you show us your settings.py code? 你能告诉我们您的settings.py代码吗? you can also try edit the path to the mysql_config file to point to /usr/local/mysql/bin/mysql_config as discussed in better detail in this article: http://dakrauth.com/blog/entry/python-and-django-setup-mac-os-x-leopard/ 您也可以尝试编辑mysql_config文件的路径以指向/ usr / local / mysql / bin / mysql_config,如本文中更详细讨论的那样: http//dakrauth.com/blog/entry/python-and-django -setup-MAC-OS-X-豹/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安装mysql:否libmysqlclient.18.dylib(OS X) - Installing mysql: No libmysqlclient.18.dylib (OS X) 找不到所需的dylib&#39;libmysqlclient.18.dylib&#39; - required dylib 'libmysqlclient.18.dylib' not found Django / mysqlclient寻找丢失的`libmysqlclient.18.dylib`文件 - Django / mysqlclient looking for missing `libmysqlclient.18.dylib` file Python mysqldb:未加载库:libmysqlclient.18.dylib - Python mysqldb: Library not loaded: libmysqlclient.18.dylib Python导入MySQLdb:库未加载:libmysqlclient.18.dylib - Python import MySQLdb: Library not loaded: libmysqlclient.18.dylib 库未加载:@rpath/libmysqlclient.21.dylib 原因:找不到图像 Django 使用 mysqlclient DB 驱动程序迁移错误和 MySQL 8 with macOS - Library not loaded: @rpath/libmysqlclient.21.dylib Reason: image not found Django migrate error using mysqlclient DB driver and MySQL 8 with macOS libmysqlclient_r.18.dylib不同于/ usr / local / mysql / lib / MacOS - libmysqlclient_r.18.dylib disaphere from /usr/local/mysql/lib/ MacOS 库未加载:/usr/local/opt/mysql/lib/libmysqlclient.21.dylib和原因映像未找到 - Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.21.dylib and Reason image not found “OSError:dlopen(libSystem.dylib,6):找不到图像”(OS X + macports + Celery 3.1.7) - “OSError: dlopen(libSystem.dylib, 6): image not found” (OS X + macports + Celery 3.1.7) libmysqlclient.16.dylib在哪里 - Where is libmysqlclient.16.dylib
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM