简体   繁体   English

为什么只运行mysql5.7的本地需要libmysqlclient.21.dylib?

[英]Why libmysqlclient.21.dylib is needed on local with only mysql5.7 running?

On my local I've got mysql@5.7 running.在我的本地我有 mysql@5.7 运行。 And I have an application which relies on mysql, but got interesting error:我有一个依赖 mysql 的应用程序,但出现了有趣的错误:

    File "/xxx/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
    from . import _mysql
    ImportError: dlopen(/xxx/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.21.dylib
    Referenced from: /xxx/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
    Reason: image not found
  1. Now only mysql@5.7 runs on my local, so I can see I've got /usr/local/opt/mysql@5.7/lib/libmysqlclient.20.dylib , but I never have /usr/local/opt/mysql/lib/libmysqlclient.21.dylib .现在只有 mysql@5.7 在我的本地运行,所以我可以看到我有/usr/local/opt/mysql@5.7/lib/libmysqlclient.20.dylib ,但我从来没有/usr/local/opt/mysql/lib/libmysqlclient.21.dylib And why is it needed here?为什么这里需要它? libmysqlclient.21.dylib is only provided by mysql8.0+ libmysqlclient.21.dylib仅由mysql8.0+提供

  2. What is site-packages/MySQLdb doing? site-packages/MySQLdb在做什么? Guess connect to my local mysql?猜猜连接到我本地的 mysql? Then why it's asking 21.dylib which doesn't exist?那么为什么它会询问不存在的21.dylib

I just ran into the same issue (using python 3.8), and thanks to Bill Karwin's answer was able to fix it by reinstalling mysqlclient with —-no-cache option, to make sure the wheel gets rebuilt:我刚刚遇到了同样的问题(使用 python 3.8),多亏了Bill Karwin 的回答,我才能够通过使用—-no-cache选项重新安装mysqlclient来修复它,以确保轮子得到重建:

pip uninstall mysqlclient
pip install mysqlclient —-no-cache

Here is the sequence of events that led to the libmysqlclient.21.dylib error in my case:在我的案例中,这是导致libmysqlclient.21.dylib错误的事件序列:

  • installed mysql via Homebrew, which installed mysql@8通过 Homebrew 安装mysql ,它安装了mysql@8
  • pip-installed a bunch of dependencies for a project, including mysqlclient pip-installed 为一个项目安装了一堆依赖,包括mysqlclient
  • realized I actually needed mysql@5.7 for the project, downgraded mysql意识到我实际上需要mysql@5.7这个项目,降级mysql
  • ran the project and saw the error about missing libmysqlclient.21.dylib because the mysqlclient wheel was built while mysql@8 was installed运行项目,看到了关于缺少libmysqlclient.21.dylib的错误,因为mysqlclient wheel 是在安装mysql@8时构建的

MySQLdb is a Python 2 module implemented in C, and it links to the libmysqlclient. MySQLdb 是 C 中实现的 Python 2 模块,它链接到 libmysqlclient。 If you have a binary of MySQLdb that was compiled against a MySQL 8.0 client library, then it would have a fixed reference to libmysqlclient21.dylib, and if that library is not present, that would cause the error you saw.如果您有一个针对 MySQL 8.0 客户端库编译的 MySQLdb 二进制文件,那么它将有一个对 libmysqlclient21.dylib 的固定引用,如果该库不存在,则会导致您看到的错误。

MySQLdb is also not compatible with Python 3, and I would hope you use Python 3 by now . MySQLdb 也不兼容 Python 3,我希望你现在使用 Python 3

You can use PyMySQL as a substitute for MySQLdb.您可以使用 PyMySQL 作为 MySQLdb 的替代品。 PyMySQL is all-Python, so it should not reference any libmysqlclient. PyMySQL 是全 Python 的,所以它不应该引用任何 libmysqlclient。

Alternatively, use MySQL-Connector Python .或者,使用MySQL-Connector Python

暂无
暂无

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

相关问题 库未加载:/usr/local/opt/mysql/lib/libmysqlclient.21.dylib和原因映像未找到 - Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.21.dylib and Reason image not found 库未加载:@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 我的 mac 上的 python mysqldb 错误:未加载库:@rpath/libmysqlclient.21.dylib - python mysqldb err on my mac :Library not loaded: @rpath/libmysqlclient.21.dylib libmysqlclient_r.18.dylib不同于/ usr / local / mysql / lib / MacOS - libmysqlclient_r.18.dylib disaphere from /usr/local/mysql/lib/ MacOS 安装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 libmysqlclient.16.dylib在哪里 - Where is libmysqlclient.16.dylib 在OS X上使用Django中的MySQL时找不到libmysqlclient.18.dylib映像 - libmysqlclient.18.dylib image not found when using MySQL from Django on OS X Python 的 MySQLdb 无法使用 Homebrewed MySQL 找到 libmysqlclient.dylib - Python's MySQLdb can’t find libmysqlclient.dylib with Homebrewed MySQL 错误库未加载:运行python应用程序时/usr/local/opt/mysql-client/lib/libssl.1.1.dylib - error Library not loaded: /usr/local/opt/mysql-client/lib/libssl.1.1.dylib when running python app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM