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 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
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
I 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?
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.
I'm running Ubuntu 12.04 and using pycharm IDE with the anaconda interpreter.
I have installed the mysql.connector module, however whenever I try to import and run the mysql.connector, I get the 'ImportError: No module named mysql.connector'.
If I run import mysql.connector within the python console I receive... Traceback (most recent call last): File "/home/my_name/anaconda2/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2885, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-2-8eb88b59635b>", line 1, in <module> import mysql.connector File "/usr/lib/pycharm-community/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) ImportError: No module named mysql.connector
The file path to the mysql connector I can find is /usr/lib/pymodules/python2.7/mysql/connector
Anyone have an idea what is going wrong here?
Thanks in advance to any replies or solutions...
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
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.