Mac 下Python import mysql库时报错的问题及处理

    xiaoxiao2021-03-25  106

    问题描述:

         Mac环境下使用pip install mysql 后在Python环境中import MySQLdb报错, 报错信息如下:    

    >>> 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

    原因分析:

         The computer security settings prevent the shared library _mysql.so from using a relative reference to the library libmysqlclient.18.dylib. In the future, the shared library _mysql.so may be updated. Until then, you can force it to use an absolute reference via the install_name_toolutility. Assuming that libmysqlclient.18.dylib is in /usr/local/mysql/lib/, then run the command:

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

    处理办法

    使用命令解决问题。

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

    转载请注明原文地址: https://ju.6miu.com/read-5228.html

    最新回复(0)