2

I am having a lot of trouble with the mysql-connector-python package. On my work laptop the package works every time without fail. However, on my personal laptop it seems to be completely random when it works. I am running a Jupyter Notebook in VS Code and using Python 3.6.2.

For example,

First I installed the mysql-connector package in the terminal with: pip install mysql-connector-python

Then I import the package with this command: import mysql.connector

Although, when I try to import the package I get this error: ModuleNotFoundError: No module named 'mysql'

If I restart my computer and then run the import it will work but after restarting the Jupyter kernel or selecting a different kernel, it will stop working until I restart my computer again.

I see this is a problem for other people too but can't seem to find the right fix for my issue. Does anybody know what's going on?

1 Answer 1

1

"mysql-connector-python" is a Python module package. When we use different Python environments, its storage location is different. Therefore, we need to select the Python kernel containing this module at the upper right of the Jupyter notebook.

Please check the Python environment you used when installing this module in the VSCode terminal, and also use this environment in Jupyter.

enter image description here

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

2 Comments

Hi thanks for the answer! I'm trying to install in a virtual environment similar to yours. In the bottom left corner it reads "Python 3.9.0 64-bit ('venv3.9': venv)" but in the top right it has "Python 3.9.0 64-bit: Idle" and doesn't include "venv" like yours. When I click to select a different kernel it doesn't include one that has "venv" in the name. Is this my issue?
@tyleroki -How did you create a virtual environment? And can the terminal successfully enter the virtual environment you created? Please try to reload VSCode.

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.