python 在 eclipse 中使用 MySQL 的问题

发布于 2024-12-12 11:41:31 字数 1243 浏览 3 评论 0原文

示例:

import MySQLdb
conn = MySQLdb.connect(passwd="passwd", db="mydb")
cursor = conn.cursor()
cursor.execute("""SELECT * FROM table""")
records = cursor.fatchone()
print records

提供下一个错误:

回溯(最近一次调用最后一次):文件
“/Applications/eclipse/plugins/org.python.pydev.debug_2.2.2.2011100512/pysrc/pydevd.py”,
第 1267 行,位于
debugger.run(setup['file'], None, None) 文件 "/Applications/eclipse/plugins/org.python.pydev.debug_2.2.2.2011100512/pysrc/pydevd.py", 第 1020 行,正在运行
pydev_imports.execfile(file, globals, locals) #执行脚本 File "/Users/user/Documents.Develop/workspace/myProject/src/Main.py",
第 56 行,位于
导入 MySQLdb 文件“build/bdist.macosx-10.7-intel/egg/MySQLdb/init.py”,第 19 行,位于
文件“build/bdist.macosx-10.7-intel/egg/_mysql.py”,第 7 行,
在文件“build/bdist.macosx-10.7-intel/egg/_mysql.py”中,行
6、在bootstrap中导入错误:
dlopen(/Users/user/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so,
2): 库未加载:libmysqlclient.18.dylib 引用自:
/Users/user/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
原因:找不到图片

错误在哪里?

Example:

import MySQLdb
conn = MySQLdb.connect(passwd="passwd", db="mydb")
cursor = conn.cursor()
cursor.execute("""SELECT * FROM table""")
records = cursor.fatchone()
print records

provides the next error:

Traceback (most recent call last): File
"/Applications/eclipse/plugins/org.python.pydev.debug_2.2.2.2011100512/pysrc/pydevd.py",
line 1267, in
debugger.run(setup['file'], None, None) File "/Applications/eclipse/plugins/org.python.pydev.debug_2.2.2.2011100512/pysrc/pydevd.py",
line 1020, in run
pydev_imports.execfile(file, globals, locals) #execute the script File "/Users/user/Documents.Develop/workspace/myProject/src/Main.py",
line 56, in
import MySQLdb File "build/bdist.macosx-10.7-intel/egg/MySQLdb/init.py", line 19, in
File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7,
in File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line
6, in bootstrap ImportError:
dlopen(/Users/user/.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/user/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
Reason: image not found

Where's the error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟的代价 2024-12-19 11:41:31

错误似乎在这里:

库未加载:libmysqlclient.18.dylib 引用自:

确保安装了 mysqldb 库。
请参阅:如何安装 MySQLdb 包? (导入错误:没有名为 setuptools 的模块)
和/或: http ://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/

您的 代码:

records = cursor.fatchone() 
--> should be
records = cursor.fetchone() 

The error seems to be here:

Library not loaded: libmysqlclient.18.dylib Referenced from:

Make sure you install the mysqldb library.
See: How to install MySQLdb package? (ImportError: No module named setuptools)
and/or: http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/

You also have a syntax error in your code:

records = cursor.fatchone() 
--> should be
records = cursor.fetchone() 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文