ModuleNotFoundError - PyMySQL for python 3

前端 未结 2 461
南笙
南笙 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)
    # ...
    
    0 讨论(0)
  • 2021-01-29 09:42

    First insall PyMySQL using:

    pip install PyMySQL
    

    In python 3 it is pymysql, all in lower case

    import pymysql
    
    0 讨论(0)
提交回复
热议问题