使用mysql报错显示Reason: im…

报错信息:


Traceback (most recent call last):
  File “/Volumes/此处省略路径信息.../test.py", line 2, in import MySQLdb as mdb File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQLdb/__init__.py", line 19, in import _mysql ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so Reason: image not found
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

报错原因:

找不到libmysqlclient.18.dylib这个文件,但这个文件在/usr/local/MySQL/lib/下是有的, 只是位置不对,于是我们这样解决.

执行命令:


sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
  • 1
  • 1

结果提示:


ln: /usr/lib/libmysqlclient.18.dylib: Operation not permitted
  • 1
  • 1

原因:

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 /Users/Victoria/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/MySQL_python-1.2.5-py2.7-macosx-10.6-x86_64.egg/_mysql.so

你可能感兴趣的:(使用mysql报错显示Reason: im…)