python - 无法导入 mysql.connector - ModuleNotFoundError:没有名为“mysql”的模块
问题描述
import mysql.connector
得到以下错误。
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
但是,下面的命令显示mysql是否已安装?
(env) bash-4.2$ pip list | grep mysql
mysql (0.0.3)
mysqlclient (2.0.3)
(env) bash-4.2$ conda list mysql
WARNING conda.core.prefix_data:_load_site_packages(272): Problem reading non-conda package record at lib/python3.6/site-packages/pyzmq-17.0.0-py3.6.egg-info/PKG-INFO. Please verify that you still need this, and if so, that this is still installed correctly. Reinstalling this package may help.
WARNING conda.core.prefix_data:_load_site_packages(272): Problem reading non-conda package record at lib/python3.6/site-packages/jupyterlab-2.3.1-py3.9.egg-info/PKG-INFO. Please verify that you still need this, and if so, that this is still installed correctly. Reinstalling this package may help.
WARNING conda.core.prefix_data:_load_site_packages(272): Problem reading non-conda package record at lib/python3.6/site-packages/conda-4.10.3-py3.6.egg-info/PKG-INFO. Please verify that you still need this, and if so, that this is still installed correctly. Reinstalling this package may help.
WARNING conda.core.prefix_data:_load_site_packages(272): Problem reading non-conda package record at lib/python3.6/site-packages/certifi-2021.5.30-py3.6.egg-info/PKG-INFO. Please verify that you still need this, and if so, that this is still installed correctly. Reinstalling this package may help.
# packages in environment at /apps/external/4/anaconda3:
#
# Name Version Build Channel
mysql 5.7.20 h55eaa98_0 https://mycompany.intranet/repository/anaconda-main-proxy
BTW,为什么pip mysql的版本这么低?(0.0.3)
解决方案
pip install mysql-connector 或不要让你的 .py 文件名:mysql.py 或类似的东西。
推荐阅读
- r - 读取管道和逗号分隔的文件:|column1|,|column2|
- c# - 是否可以模拟从测试类单元间接调用的类的方法?
- c# - NameValueCollection 到 ConfigurationSection
- hive - 将两个文件作为一个文件存储到 hdfs
- ios - 注册/登录表单中的密码字段是“完成”还是“开始”?
- sql - Lognest 日期序列/组序列
- html - 如何在 CSS 和 HTML 中打断长词
- bigdata - 加拿大的地理图表在 GoodData 中不起作用。有什么替代解决方案吗?
- android - 使用 Android Studio 3.XX,将本地 .AAR 文件添加到 Gradle 构建不起作用
- javascript - 如何从 Ant Design 中的菜单项悬停中删除突出显示?