python 2.7中安装mysql

在python中进行安装mysql模块,但是怎么都不能导入mysql模块,出错如下所示:

 

[root@python ~]# python
Python 2.7.11 (default, Apr  5 2016, 12:24:31) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] 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


检查安装包:

 

 

[root@python ~]# rpm -qa MySQL-python
MySQL-python-1.2.3-0.3.c1.1.el6.x86_64


发现在操作系统中已经安装了Mysql-python的包,但是依然不能导入的。。。

 

 

安装mysql-python模块:

 

 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包,从而安装此包:

 

[root@python ~]# yum -y install mysql-devel

 

再次进行安装mysql-python模块:

 

[root@python ~]# 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包即可导入。

 

[root@python ~]# python
Python 2.7.11 (default, Apr  5 2016, 12:24:31) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> 

公众号:SRE艺术

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值