Python3 mySQL.connector frozen import lib

在学习python3操作mysql中遇到问题,代码入下:

import mysql.connector
#创建mysql链接
conn = mysql.connector.connect(user='root',password='root',database='python',use_unicode=True)
cursor = conn.cursor()
#创建user表
#cursor.execute('create table user_test(user_id varchar(20) primary key,user_name varchar(20))')
#插入记录
cursor.execute('insert into user_test(user_id,user_name) values(%s,%s)',['2','Jerry'])
cursor.rowcount

#提交事务
conn.commit()
cursor.close()

 运行时提示错误:

Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "mysql.py", line 3, in <module>
import mysql.connector
File "D:\python\mysql.py", line 3, in <module>
import mysql.connector
ImportError: No module named 'mysql.connector'; 'mysql' is not a package

原因竟然是因为我写的测试文件的名称是 msyql.py 和已有的包mysql重名了哭,谨记。

参考:http://stackoverflow.com/questions/16055274/python-3-mysql-connector-frozen-import-lib

你可能感兴趣的:(mysql,python)