MYSQLLinux与后台开发归档

[MYSQL]MAC下Python import mysql库时

2018-08-18  本文已影响47人  _小老虎_

mac下安装好了mysql和python的 mysql-python后,发现运行报错:
我是用dmg安装的mysql 5.6

>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Library/Python/2.7/site-packages/_mysql.so
  Reason: unsafe use of relative rpath libmysqlclient.18.dylib in /Library/Python/2.7/site-packages/_mysql.so with restricted binary

上网查了好久,很多人都是只会复制粘贴 不解决根本问题,所以找了好久才找到解决方法:

sudo install_name_tool -change libmysqlclient.18.dylib  /usr/local/mysql/lib/libmysqlclient.18.dylib  /Library/Python/2.7/site-packages/_mysql.so
上一篇下一篇

猜你喜欢

热点阅读