我已成功下载 Connector/Python for MySQL。我在 Python 的 shell 中使用以下代码来测试我的连接:
import mysql.connector
我收到以下错误消息:
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import mysql.connector
ImportError: No module named 'mysql'
我不明白为什么 MySQL 不被识别。
我面临着类似的问题。我的环境详细信息 -
Python 2.7.11
点 9.0.1
CentOS 版本 5.11(最终版)
python 解释器出错 -
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mysql.connector
>>>
使用 pip 搜索可用模块 -
$ 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
安装 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
>>>
谢谢=)
对于 python3 及更高版本,请使用以下命令:
$ pip3 安装 mysql-connector-python-rf
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)