简体   繁体   English

mysql-connector-python 不适用于 VS Code 并在 python shell 中工作

[英]mysql-connector-python is not working on VS Code and working in python shell

I am trying to connect to MySQL database, but strangly mysql-connector-python is working in python shell, and not using VS Code.我正在尝试连接到 MySQL 数据库,但奇怪的是mysql-connector-python正在 python shell 中工作,而不是使用 VS Code。

I tried installing the following packages:我尝试安装以下软件包:

pip install mysql-connector
pip install mysql-connector-python
pip install mysql-connector-python-rf

No luck either.也没有运气。 So, I uninstalled all packages then reinstalled only mysql-connector-python , then rebooted, to make sure there was no issue in this regard.因此,我卸载了所有软件包,然后仅重新安装了mysql-connector-python ,然后重新启动,以确保在这方面没有问题。

The error is:错误是:

ModuleNotFoundError: No module named 'mysql.connector'; 'mysql' is not a package

Python version: 3.9.4 VS Code: 1.6.20 Python 版本:3.9.4 VS 代码:1.6.20

Here are some screenshots:以下是一些截图:

在此处输入图片说明

在此处输入图片说明

The main issue was related to code runner.主要问题与代码运行器有关。 uninstall, then install did the trick.卸载,然后安装就行了。

I often face some error because of code runner not connecting to the right environment or not reading new package.由于代码运行器未连接到正确的环境或未读取新包,我经常面临一些错误。 Normally, restarting the visual studio code session or the whole software solve it, but not in this case.通常,重新启动 Visual Studio 代码会话或整个软件可以解决它,但在这种情况下不会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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