python导入模块报错:ImportError: No module named mysql.connector(安装 mysql)

python的版本是

$ python --version
Python 2.7.12

报错代码如下

import mysql.connector

报错信息是

ImportError: No module named mysql.connector

开始时安装的驱动是,安装成功

$ pip install mysql-connector

但是如果要是安装 mysql-connector-python就会报错

Collecting mysql-connector-python
Could not find a version that satisfies the requirement mysql-connector-python (from versions: )
No matching distribution found for mysql-connector-python

所以现在使用的驱动是 mysql-connector 而不是 mysql-connector-python
求助有经验的朋友!!

问题已解决

步骤如下:

执行pip search mysql-connector | grep --color mysql-connector-python

输出信息是这样的

mysql-connector-python-rf (2.1.3)        - MySQL driver written in Python
mysql-connector-python (2.0.4) - MySQL driver written in Python

使用pip install mysql-connector-python-rf==2.1.3就可以了

上一篇:【转】解决编译安装NGINX时make报错


下一篇:python pip安装模块报错 "Can't connect to HTTPS URL because the SSL module is not available."