zl程序教程

您现在的位置是:首页 >  其它

当前栏目

module ‘pymysql‘ has no attribute ‘connect‘

No module has attribute connect pymysql
2023-09-11 14:14:27 时间

之前试试用python 连接 mysql ,用到了pymysql模块,程序如下:


  
  
  1. import pymysql
  2. connection = pymysql.connect( 'localhost', 'root', '123456', 'python_opmysql')
  3. sql = "create table wee (name varchar(10), age int(2));"
  4. cursor = connection.cursor()
  5. cursor.execute(sql)
  6. connection.commit()
  7. connection.close()

然后报错了:

AttributeError: module 'pymysql' has no attribute 'connect' 

找了十多分钟,,然后发现一个问题:

文件和模块重名了。。。(难怪自动联想也没弹出来,,,)

â好尴尬å 表æåâçå¾çæç´¢ç»æ

把文件名字改掉: 

运行成功: