0

I am trying to connect to MySQL database, but strangly mysql-connector-python is working in python shell, and not using 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.

The error is:

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

Python version: 3.9.4 VS Code: 1.6.20

Here are some screenshots:

enter image description here

enter image description here

4
  • I ran my python script in terminal (not using code runner), same issue. Commented Sep 30, 2021 at 12:58
  • I connected to MySQL using pyodbc package, but still no luck with mysql Commented Oct 5, 2021 at 21:04
  • Uninstall mysql-connector and mysql-connector-python-rf. The official (and maintained) MySQL connector is mysql-connector-python. Also check that you're not using a different Python version in VS Code. In the screenshots I see you're using a custom Python installation and VS Code is using the anaconda3. Commented Nov 23, 2021 at 9:49
  • I tried exactly that. Code runner extension is what causing the problem. So, when I execute in terminal my code run smoothly. I believe code runner not connecting to the correct environment. I don't know why yet. Thank you so much for you reply. Commented Nov 24, 2021 at 10:05

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.