import mysql.connector
另外,我不太确定
PyCharm 3.7 是什么?您是指 Python 3.7 和 PyCharm 2019? (对于这个答案,我使用 PyCharm Professional 2019 和 Python 3.6
对我来说,问题是我安装了
mysql-connector
pip3
使用错误的 pip 将使您的包无法用于其他 python 版本。检查您的 python 安装版本。如果您有多个版本,请务必使用相关的正确 pip 版本。
pip show mysql-connector-python
# or
pip3 show mysql-connector-python
如果返回:
警告:未找到包:mysql-connector-python
然后运行
pip install mysql-connector-python
# or
pip3 install mysql-connector-python
重新运行第一个命令,您现在应该看到类似这样的内容:
>>> pip show mysql-connector-python
Name: mysql-connector-python
Version: 8.3.0
Summary: MySQL driver written in Python
Home-page: http://dev.mysql.com/doc/connector-python/en/index.html
Author: Oracle and/or its affiliates
Author-email:
License: GNU GPLv2 (with FOSS License Exception)
Location: C:\Users\JayRizzo\AppData\Roaming\Python\Python311\site-packages
Requires:
Required-by: