python 2.7中安装mysql
在python中进行安装mysql模块,但是怎么都不能导入mysql模块,出错如下所示:view plain copy
[*] # python
[*] Python 2.7.11 (default, Apr5 2016, 12:24:31)
[*] on linux2
[*] Type "help", "copyright", "credits" or "license" for more information.
[*] >>> import MySQLdb
[*] Traceback (most recent call last):
[*] File "<stdin>", line 1, in <module>
[*] ImportError: No module named MySQLdb
检查安装包:
view plain copy
[*] # rpm -qa MySQL-python
[*] MySQL-python-1.2.3-0.3.c1.1.el6.x86_64
发现在操作系统中已经安装了Mysql-python的包,但是依然不能导入的。。。
安装mysql-python模块:
view plain copy
[*] error: command 'gcc' failed with exit status 1
[*]
[*] ----------------------------------------
[*] Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-OcAYDJ/mysql-python/setup.py';
[*] exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))"
[*] install --record /tmp/pip-Urb3hW-record/install-record.txt --single-version-externally-managed --compile"
[*] failed with error code 1 in /tmp/pip-build-OcAYDJ/mysql-python/
在进行pip jinstall musql-python的时候就是出错!!!报错内容如上。
出错的原因是因为必须安装mysql-python包,从而安装此包:
view plain copy
[*] # yum -y install mysql-devel
再次进行安装mysql-python模块:
view plain copy
[*] # pip install mysql-python
[*] Collecting mysql-python
[*] Using cached MySQL-python-1.2.5.zip
[*] Installing collected packages: mysql-python
[*] Running setup.py install for mysql-python ... done
[*] Successfully installed mysql-python-1.2.5
成功安装。
在使用pip安装的模块的时候,如果需要卸载,那么只要pip uninstall packagename即可,还是蛮方便的。
此问题在2.7版本中发现,在2.6版本中仅仅需要安装mysql-python包即可导入。
view plain copy
[*] # python
[*] Python 2.7.11 (default, Apr5 2016, 12:24:31)
[*] on linux2
[*] Type "help", "copyright", "credits" or "license" for more information.
[*] >>> import MySQLdb
[*] >>>
[*]
页:
[1]