[英]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
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+
提供
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
错误的事件序列:
mysql
via Homebrew, which installed mysql@8
mysql
,它安装了mysql@8
mysqlclient
mysqlclient
mysql@5.7
for the project, downgraded mysql
mysql@5.7
这个项目,降级mysql
libmysqlclient.21.dylib
because the mysqlclient
wheel was built while mysql@8
was installedlibmysqlclient.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.