美文网首页MYSQLLinux与后台开发归档
[MYSQL]MAC下Python import mysql库时

[MYSQL]MAC下Python import mysql库时

作者: _小老虎_ | 来源:发表于2018-08-18 21:35 被阅读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
    

    相关文章

      网友评论

        本文标题:[MYSQL]MAC下Python import mysql库时

        本文链接:https://www.haomeiwen.com/subject/vvhqiftx.html