【问题标题】:spyder mysql connector pythonspyder mysql 连接器 python
【发布时间】:2016-01-16 08:26:26
【问题描述】:

我在使用 Anaconda Spyder IDE 时遇到了用于 python 2.7 的 mysql-connector 的问题。虽然下面的代码在 Python Gui 中有效,但我在 spyder 中收到以下错误:'ImportError: No Module named mysql.connector'。

代码如下:

import mysql.connector
conn=mysql.connector.connect(user='root',password='xxxxx',host='localhost',database='xxxxx')
mycursor=conn.cursor()

mycursor.execute("""SELECT Ir FROM FinProg where ProgCatId = 4""")
obrrate = mycursor.fetchall().

我通过命令行在 spyder 上下载了 mysql 连接器:'conda install mysql-python'。

spyder 是否需要不同的语法才能使用 mysql-connector?如何将 mysql-connector 用于 spyder?

【问题讨论】:

    标签: python-2.7 anaconda mysql-connector spyder mysql-connector-python


    【解决方案1】:

    好的,我在 spyder 中使用了不同的代码语法,它终于奏效了。这是spyder python 2.7中的成功代码: 导入 MySQL 数据库 conn=MySQLdb.connect(host='localhost',user='root',passwd='xxxxx',db='xxxxx') mycursor=conn.cursor()

    【讨论】:

      【解决方案2】:

      您使用 MySQLdb 的解决方案可能对您来说效果很好,但需要澄清一下:

      MySQLdb 和 MySQL.Connector 是 MySQL 和 Python 的两个不同端口。您问题中的代码似乎是 MySQL.Connector 的有效语法,对于 Spyder,该语法是通过

      安装的

      conda 安装 mysql-connector-python

      【讨论】:

        【解决方案3】:

        使用 pip install mysql-connector-python in

        【讨论】:

        • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。
        【解决方案4】:

        首先,在 Spyder IPython 控制台(执行完成的地方)中运行pip install mysql-connector 命令,执行完成后重新启动内核,然后您可以使用import mysql.connector。

        【讨论】:

          猜你喜欢
          • 2019-06-15
          • 2018-06-27
          • 1970-01-01
          • 2021-07-04
          • 1970-01-01
          • 2019-07-19
          • 2014-12-10
          • 1970-01-01
          • 2020-08-16
          相关资源
          最近更新 更多