Home > Software design >  How to fix "Error: No module named mysql.connector"
How to fix "Error: No module named mysql.connector"

Time:03-10

I am working with some python program where I need to import mysql.connector. But I am facing ImportError: No module named connector. I already read answers on same issue and also explore google to find out and try some step to fix still it not fixed.

I am working on MacOS. and I guess by default python 2.7.18 is installed and also I installed python 3.8.9.

So I came to know that I have to install pip install mysql-connector for python 2.X but when I ran this in my terminal it is showing command not found: pip . Then I tried to install pip3 install mysql-connector. for python3 and it got successfully installed.

But Still problem not fixed. Any idea how to fix this?

CodePudding user response:

It could be the case where you are running the Python file with the wrong Python installation. In VS Code we can choose the interpreter using which we want to run our Python file.

By default, the Python extension looks for and uses the first Python interpreter it finds in the system path. To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl Shift P).

Just choose Python 3.8.9 from the list of interpreters. For complete guide you can refer to the documentation: https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment

CodePudding user response:

You got two Python installed in your system. Python3 and Python2. Pip3 is just for python3. You must use pip2 or pip2.7 for work with python2. Search if you got the pip2 package installed is not then install it.

  • Related