ModuleNotFoundError - PyMySQL for python 3

北城以北 提交于 2019-12-11 15:57:48

问题


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'm getting:

import PyMySQL ModuleNotFoundError: No module named 'PyMySQL'.

it can be found when i run the command pip list, but not found when running the program itself. I was perusing over other SO Q&A's but nothing helped. Thanks


回答1:


First insall PyMySQL using:

pip install PyMySQL

In python 3 it is pymysql, all in lower case

import pymysql



回答2:


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)
# ...


来源:https://stackoverflow.com/questions/48647617/modulenotfounderror-pymysql-for-python-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!