为了账号安全,请及时绑定邮箱和手机立即绑定

找不到名为游标的模块

找不到名为游标的模块

婷婷同学_ 2021-04-06 17:19:34
我只是在VPS上安装了PyMySQL,安装似乎没有任何问题。为了确保一切正常,我尝试执行在他们的文档中找到的以下脚本。Python 2.7.5 和 Python 3.6.5Server version: 10.1.34-MariaDB MariaDB Serverimport pymysql.cursors# Connect to datebasecon = pymysql.connect(host='localhost',                    user='dbuser',                    password='dbpass',                    db='dbname',                    charset='utf8mb4',                    cursorclass=pymysql.cursor.DictCursor)try:    with con.cursor() as cursor:        # Create new record        sql = "INSERT INTO `test` (`idx`, `title`, `description`, `category`) VALUES (%s, %s, %s, %s)"        cursor.execute(sql, (1, 'Fake Title', 'Fake description about a fake post.', 'WELLNESS'))    with con.cursor() as cursor:        # Read a single record        sql = "SELECT `idx`, `title` FROM `test` WHERE `idx`=%s"        cursor.execute(sql, ('1'))        result = cursor.fetchone()finally:    with open('dbText.txt', 'w') as f:        f.write('%s'.format(result))        con.close()但是,我收到一个ImportError,显示为No module found named cursors。[root@host public_html]# python pymysql.pyTraceback (most recent call last):    File "pymysql.py", line 1, in <module>        import pymysql.cursors    File "/home/bldsprt/public_html/pymysql.py", line 1, in <module>        import pymysql.cursorsImportError: No module named cursors[root@host public_html]# python3.6 pymysql.pyTraceback (most recent call last):  File "pymysql.py", line 1, in <module>    import pymysql.cursors  File "/home/bldsprt/public_html/pymysql.py", line 1, in <module>    import pymysql.cursorsModuleNotFoundError: No module named 'pymysql.cursors'; 'pymysql' is not a package我需要cursors单独安装模块吗?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 134 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信