【问题标题】:python issues with MySQL in eclipseeclipse中MySQL的python问题
【发布时间】:2011-12-16 11:23:36
【问题描述】:

例子:

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

提供下一个错误:

Traceback(最近一次调用最后一次):文件
"/Applications/eclipse/plugins/org.python.pydev.debug_2.2.2.2011100512/pysrc/pydevd.py",
第 1267 行,在
debugger.run(setup['file'], None, None) File "/Applications/eclipse/plugins/org.python.pydev.debug_2.2.2.2011100512/pysrc/pydevd.py", 第 1020 行,正在运行
pydev_imports.execfile(file, globals, locals) #执行脚本文件“/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 ImportError:
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
原因:找不到图片

哪里出错了?

【问题讨论】:

  • 也许records = cursor.fatchone() 应该改为records = cursor.fetchone()

标签: python mysql eclipse pydev mysql-python


【解决方案1】:

错误似乎在这里:

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

确保安装了 mysqldb 库。
见:How to install MySQLdb package? (ImportError: No module named setuptools)
和/或:http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/

您的代码中还有语法错误:

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

【讨论】:

    猜你喜欢
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    • 2011-09-01
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    相关资源
    最近更新 更多