python mysqldb err on my mac :Library not loaded: @rpath/libmysqlclient.21.dylib

廉价感情. 提交于 2020-04-17 18:32:07

问题


import MySQLdb

leads to

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.13-intel/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.13-intel/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.13-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/simon/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.13-intel.egg-tmp/_mysql.so, 2): Library not loaded: @rpath/libmysqlclient.21.dylib
  Referenced from: /Users/simon/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.13-intel.egg-tmp/_mysql.so
  Reason: image not found`

I try to build and install mysql-python, and ln -s /usr/local/mysql/lib/libmysqlclient.18.dyli, but can not resolve it


回答1:


So, from what I can tell, the @rpath tries to resolve to /usr/lib, which can't be written to. I resolved this by crawling through this site. A lot of it is in Chinese, but what I got was the command sudo install_name_tool -change @rpath/libmysqlclient.21.dylib /usr/local/mysql/lib/libmysqlclient.21.dylib /Users/[username]/.pyenv/versions/career/lib/python2.7/site-packages/_mysql.so




回答2:


I did something similar to what Sam did and was able to make it work.

I simply made a copy of the libmysqlclient.21.dylib file located in my up-to-date installation of MySQL 8.0.13 which is was in /usr/local/mysql/lib and moved that copy under the same name to /usr/lib.

You will need to temporarily disable security integrity protection on your mac however to do this since you won't have or be able to change permissions to anything in /usr/lib without disabling it. You can do this by booting up into the recovery system, click Utilities on the menu at the top, and open up the terminal and enter csrutil disable into the terminal. Just remember to turn security integrity protection back on when you're done doing this! The only difference from the above process will be that you run csrutil enable instead.

You can find out more about how to disable and enable macOS's security integrity protection here.



来源:https://stackoverflow.com/questions/51002735/python-mysqldb-err-on-my-mac-library-not-loaded-rpath-libmysqlclient-21-dylib

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