I was facing the similar issue. My env details - Python 2.7.11 pip 9.0.1 CentOS release 5.11 (Final)
Error on python interpreter -
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mysql.connector
>>>
Use pip to search the available module -
$ pip search mysql-connector | grep --color mysql-connector-python
mysql-connector-python-rf (2.2.2) - MySQL driver written in Python
mysql-connector-python (2.0.4) - MySQL driver written in Python
Install the mysql-connector-python-rf -
$ pip install mysql-connector-python-rf
Verify
$ python
Python 2.7.11 (default, Apr 26 2016, 13:18:56)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>>
Answer from Rishi on Stack OverflowI am starting with Python and did short script in VScode. When I try to run it I get this error:
PS C:\Users\spider> & C:/Python39/python.exe c:/Users/spider/drek.pyTraceback (most recent call last):File "c:\Users\spider\drek.py", line 5, in <module>import mysql.connectorModuleNotFoundError: No module named 'mysql'
I ran pip install mysql-connector and it installed it. If I run pip list I get this:
PS C:\Users\spider> pip list
Package Version---------------------- -------mysql-connector 2.2.9mysql-connector-python 8.0.24pip 21.0.1protobuf 3.15.8six 1.15.0wheel 0.36.2
PS C:\Users\spider>
Why I can't use MySql commands and how to fix it?
I was facing the similar issue. My env details - Python 2.7.11 pip 9.0.1 CentOS release 5.11 (Final)
Error on python interpreter -
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mysql.connector
>>>
Use pip to search the available module -
$ pip search mysql-connector | grep --color mysql-connector-python
mysql-connector-python-rf (2.2.2) - MySQL driver written in Python
mysql-connector-python (2.0.4) - MySQL driver written in Python
Install the mysql-connector-python-rf -
$ pip install mysql-connector-python-rf
Verify
$ python
Python 2.7.11 (default, Apr 26 2016, 13:18:56)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>>
Depending on your python version and how you installed it, it is possible that mysql connector isn't installed, you can install it with pip
To install mysql connector:
pip install mysql-connector-python
Check for the current Python Interpreter VSCode is using
Ctrl+P.Add your virtual environment PATH where your module is installed in
'C:\Users\<username>\.virtualenvs\<virtualenvname>\Scripts\python'.
You need to add your current working directory to the Python search path. This can be done with an environment variable:
export PYTHONPATH=.
There is a similar question here: Import "flask" could not be resolved from sourcePylancereportMissingModuleSource
I already did the whole pip install mysql-connector-python thing, but the error’s still haunting me. How am I supposed to sleep in peace. Need help
You might want to check out the following article:
Can not get mysql-connector-python to install in virtualenv (Stackoverflow)
The accepted answer states the following:
Several things. There is an inconsistency in package naming so you may want to do:
pip search mysql-connectorto find out what it is called on your platform. I got two results
mysql-connector-pythonandmysql-connector-repackaged.so try this first:
pip install mysql-connector-pythonthis may additionally give an error like this:
Some externally hosted files were ignored (use --allow-external mysql-connector-python to allow).so finally this should do the job:
pip install mysql-connector-python --allow-external mysql-connector-python
The following command solved the issue for me.
pip install mysql-connector-python-rf
This post expands a little on the differences between mysql-connector-python and the -rf suffixed variant.