Python mysqldb:未加载库:libmysqlclient.18.dylib我刚刚在我的mac os 10.6上为python 2.7编译并安装了mysqldb。我创建了一个导入的简单测试文件import MySQLdb as mysql首先,这个命令带有红色下划线,信息告诉我“Unresolved import”。然后我尝试运行以下简单的python代码import MySQLdb as mysqldef main():
conn = mysql.connect( charset="utf8", use_unicode=True, host="localhost",user="root", passwd="",db="" )if __name__ == '__main__'():
main()执行时,我收到以下错误消息Traceback (most recent call last):
File "/path/to/project/Python/src/cvdv/TestMySQLdb.py", line 4, in <module>
import MySQLdb as mysql File "build/bdist.macosx-10.6-intel/egg/MySQLdb/__init__.py", line 19, in <module>
\namespace cvdv File "build/bdist.macosx-10.6-intel/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.6-intel/egg/_mysql.py", line 6, in __bootstrap__ImportError: dlopen(/Users/toom/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/toom/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so Reason: image not found什么可能解决我的问题?编辑:其实我发现该库位于/ usr / local / mysql / lib中。所以我需要告诉我的pydev eclipse版本在哪里找到它。我在哪里设置这个?
3 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
我发现这个问题还有另一个解决方案,而不是创建一个符号链接。
将libmysqlclient.18.dylib所在目录的路径设置为DYLD_LIBRARY_PATH环境变量。我做的是在我的.bash_profile中添加以下行:
export DYLD_LIBRARY_PATH=/usr/local/mysql-5.5.15-osx10.6-x86/lib/:$DYLD_LIBRARY_PATH
而已。
添加回答
举报
0/150
提交
取消