Python's MySQLdb can’t find libmysqlclient.dylib with Homebrewed MySQL

两盒软妹~` 提交于 2019-12-02 16:47:56

This solved my issue on my case:

$ pip uninstall MySQL-python
$ pip install mysqlclient

MySQL-python turned out to be very old (last commit was 7 years ago). mysqlclient is the modern version of it, with lots of improvements and bug fixes.

Aplusplus

I also encountered this problem. I uninstalled the MySQL-python, and then installed it.

pip uninstall MySQL-python
pip install MySQL-python

Update (based on comments)

In some cases, you may need to perform the second (install) step in the following manner:

pip install --no-binary MySQL-python MySQL-python

The no-binary option is so that pip builds it fresh and links to the correct library:

--no-binary <format_control>

Do not use binary packages. Can be supplied multiple times, and each time adds to the existing value. Accepts either :all: to disable all binary packages, :none: to empty the set, or one or more package names with commas between them. Note that some packages are tricky to compile and may fail to install when this option is used on them.

NB: Note, that MySQL-python needs to be mentioned twice. As mentioned above, the first occurrence is the name of the package to apply the no-binary option to, the second specifies the package to install.

You need to use dev version of mysqlclient:

pip install git+https://github.com/PyMySQL/mysqlclient-python.git@master

Before I had the lastest PyPI version (1.3.7) on Python 3.4 and it was searching for libmysqlclient.18.dylib (from MySQL 5.6) whereas I had only libmysqlclient.20.dylib(from MySQL 5.7).

If you use Python 3, MySQL-python is not an option (and mysqlclient is its newer version).

Dar Ben-Tov

If encountered a problem with lacking of libmysqlclient.18.dylib:

  1. download mysql 5.6 from official link: https://dev.mysql.com/downloads/mysql/

  2. install it

  3. in terminal - mdfind libmysqlclient | grep .18.

  4. copy the output

  5. sudo ln -s [the output from previous command] /usr/local/lib/libmysqlclient.18.dylib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!