【问题标题】:Cannot import mysql.connector - ModuleNotFoundError: No module named 'mysql'无法导入 mysql.connector - ModuleNotFoundError:没有名为“mysql”的模块
【发布时间】:2021-11-29 21:34:06
【问题描述】:

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)

【问题讨论】:

  • 不确定,但docs on web 表示您可能需要conda install mysql-connector-python

标签: python mysql pip anaconda conda


【解决方案1】:

pip 安装 mysql-connector 要么 不要让你的 .py 文件名:mysql.py 或类似的东西。

【讨论】:

    【解决方案2】:

    操作系统:Mac 11.6.2(大苏尔) Python:3.9.7

    如果你和我一样使用 conda 环境,并且在安装 mysql-connector-python 模块时遇到问题,请尝试以下操作:

    (env)username ~% conda update --all
    (env)username ~% conda uninstall mysql
    (env)username ~% conda install -c conda-forge mysql
    (env)username ~% conda install -c conda-forge mysql-connector-python
    

    现在,当从 VSCode 或 Anaconda Navigator 运行时,可以从 JupyterLab 笔记本中找到 mysql.connector 包。

    我希望这对某人有用。

    【讨论】:

      猜你喜欢
      • 2021-12-14
      • 1970-01-01
      • 2019-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多