现在的位置: 首页 > 综合 > 正文

Python: MySQLdb and “Library not loaded: libmysqlclient.16.dylib”

2017年10月21日 ⁄ 综合 ⁄ 共 1247字 ⁄ 字号 评论关闭

转自 http://stackoverflow.com/questions/4559699/python-mysqldb-and-library-not-loaded-libmysqlclient-16-dylib

在mac os上用port 方式安装了py27-mysql,之后调用的时候有如下问题:

Traceback (most recent call last):
  File "txt2db.py", line 4, in <module>
    import controlMysql as cm
  File "../controlMysql.py", line 4, in <module>
    import MySQLdb
  File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/huangwaleking/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/huangwaleking/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
  Reason: image not found

按照 stakcoverflow lukmdo 的介绍修复了问题:

Just set the DYLD_LIBRARY_PATH after
running pip
install
 or easy_install:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

Should do the job assuming your MySQL installation lives under /usr/local/mysql.

按照stackoverflow http://stackoverflow.com/questions/5081574/modifying-dyld-library-path-for-mysql-python-and-django
Matt Manoj 的解决方案解决了terminal每次需要重新export上述系统变量的问题:
sudo vi /etc/profile
追加一行:export
DYLD_LIBRARY_PATH=/usr/local/mysql/lib

抱歉!评论已关闭.