首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python | MySQL | AttributeError:模块'mysql.connector‘没有'connect’属性

Python | MySQL | AttributeError:模块'mysql.connector‘没有'connect’属性
EN

Stack Overflow用户
提问于 2019-12-04 20:50:32
回答 2查看 3.1K关注 0票数 0

我正在学习一个新的python库mysql。我已经尝试执行以下命令,

代码语言:javascript
运行
复制
import mysql.connector

mydb= mysql.connector.connect(
            host= 'localhost',
            user= 'root',
            passwd= 'skviknesh'
            )
print(mydb)

并得到了下面的错误!

代码语言:javascript
运行
复制
Traceback (most recent call last):

  File "<ipython-input-1-f9b9bc67dd68>", line 3, in <module>
    mydb= mysql.connector.connect(

AttributeError: module 'mysql.connector' has no attribute 'connect'

我调查了其他类似的堆栈溢出问题...没有得到解决方案。我也试着重命名我的文件,但没有帮助。请帮助我!

EN

回答 2

Stack Overflow用户

发布于 2020-04-16 22:13:43

当您安装了错误的软件包时,通常会发生这种情况。可能在安装过程中,您使用了以下pip命令:pip install mysql-connector

但是你需要安装这个包:pip install mysql-connector-python

如下所示:

代码语言:javascript
运行
复制
C:\Users\tuhin Mitra>pip install mysql-connector-python
Requirement already satisfied: mysql-connector-python in c:\users\tuhin mitra\appdata\local\programs\python\python37-32\lib\site-packages (8.0.19)
Requirement already satisfied: protobuf==3.6.1 in c:\users\tuhin mitra\appdata\local\programs\python\python37-32\lib\site-packages (from mysql-connector-python) (3.6.1)
Requirement already satisfied: dnspython==1.16.0 in c:\users\tuhin mitra\appdata\local\programs\python\python37-32\lib\site-packages (from mysql-connector-python) (1.16.0)
Requirement already satisfied: setuptools in c:\users\tuhin mitra\appdata\local\programs\python\python37-32\lib\site-packages (from protobuf==3.6.1->mysql-connector-python) (45.1.0)
Requirement already satisfied: six>=1.9 in c:\users\tuhin mitra\appdata\roaming\python\python37\site-packages (from protobuf==3.6.1->mysql-connector-python) (1.12.0)
票数 0
EN

Stack Overflow用户

发布于 2020-12-23 03:24:14

当我遇到同样的问题时。我只需要用pip uninstall mysql-connector-python卸载包,然后用pip install mysql-connector-python重新安装它,它就起作用了:D

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59176479

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档