![](/img/trans.png)
[英]import mysql.connector ModuleNotFoundError: No module named 'mysql'
[英]Cannot import mysql.connector - ModuleNotFoundError: No module named '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 或類似的東西。
操作系統:Mac 11.6.2 (Big Sur) Python:3.9.7
如果您像我一樣使用 conda 環境,並且在安裝 mysql-connector-python 模塊的情況下安裝現有 mysql 模塊時遇到問題,請嘗試以下操作:
(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 notebook 時,可以從 JupyterLab notebook 中找到 mysql.connector 包。
我希望這對某人有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.