ModuleNotFoundError - PyMySQL for python 3

前端 未结 2 495
南笙
南笙 2021-01-29 09:18

I am trying to get a simple test program working on my machine that connects to a SQL DB. I pip installed and then uninstalled and then installed with pip3: pymysql. the issue I

2条回答
  •  攒了一身酷
    2021-01-29 09:41

    Module names are case-sensitive, and if you take a look at this example in the GitHub repo, you'll see that the module should be imported as pymysql, which is consistent with the all-lowercase convention for modules spelled out in the PEP 8 style guide.

    import pymysql.cursors
    
    # Connect to the database
    connection = pymysql.connect(host='localhost',
                                 user='user',
                                 password='passwd',
                                 db='db',
                                 charset='utf8mb4',
                                 cursorclass=pymysql.cursors.DictCursor)
    # ...
    

提交回复
热议问题