We Are Going To Discuss About ImportError: No module named ‘MySQL’. So lets Start this Python Article.
ImportError: No module named ‘MySQL’
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 >>>
Thanks =)
For python3 and later use the next command:
$ pip3 install mysql-connector-python-rf
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 >>>
Thanks =)
For python3 and later use the next command:
$ pip3 install mysql-connector-python-rf
Solution 1
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
>>>
Thanks =)
For python3 and later use the next command:
$ pip3 install mysql-connector-python-rf
Original Author Rishi Of This Content
Solution 2
Use
pip3 install mysql-connector
to install the python packaged (if you are using Python 3. For Python 2 you can use pip
).
Original Author ilexcel Of This Content
Solution 3
May be simple install from cli?
pip3 install mysql-connector-python-rf
Package name differs from import library name
Or my universal variant in code:
import pip
pip.main(['install','mysql-connector-python-rf'])
For new version of pip:
from pip._internal import main
main(['install','mysql-connector-python-rf'])
It’s better – install needed modules in running python installation (if many)
Original Author Алексей Присяжный Of This Content
Solution 4
The silly mistake I had done was keeping mysql.py
in same dir. Try renaming mysql.py
to another name so python
don’t consider that as module.
Original Author Deepak Chauhan Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.