我刚刚在我的 mac os 10.6上编译并安装了 python 2.7的 mysqldb。我创建了一个简单的导入测试文件
import MySQLdb as mysql
首先,这个命令是红色下划线,信息告诉我“未解决的导入”。然后我尝试运行以下简单的 python 代码
import MySQLdb as mysql
def 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 版本在哪里可以找到它。我要把这个放在哪里?