简体   繁体   中英

Cannot import mysql.connector - ModuleNotFoundError: No module named 'mysql'

import mysql.connector got the following error.

import mysql.connector
ModuleNotFoundError: No module named 'mysql'

However, the following commands show the mysql is installed?

(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, why the version of pip mysql is so low? (0.0.3)

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

OS: Mac 11.6.2 (Big Sur) Python: 3.9.7

If you, like me, use conda environments, and you have trouble installing the mysql-connector-python module with an existing mysql module installed, try this:

(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

Now the mysql.connector package is found from the JupyterLab notebook when running it from either VSCode or from Anaconda Navigator.

I hope this is useful for someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM