python 2.7中安装mysql

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

[python]  view plain copy print ?
  1. [root@python ~]# python  
  2. Python 2.7.11 (default, Apr  5 201612:24:31)   
  3. [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2  
  4. Type "help""copyright""credits" or "license" for more information.  
  5. >>> import MySQLdb  
  6. Traceback (most recent call last):  
  7.   File "<stdin>", line 1in <module>  
  8. ImportError: No module named MySQLdb  

检查安装包:

[python]  view plain copy print ?
  1. [root@python ~]# rpm -qa MySQL-python  
  2. MySQL-python-1.2.3-0.3.c1.1.el6.x86_64  

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


安装mysql-python模块:

[python]  view plain copy print ?
  1.  error: command 'gcc' failed with exit status 1  
  2.       
  3.     ----------------------------------------  
  4. Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-OcAYDJ/mysql-python/setup.py';  
  5. exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n''\n'), __file__, 'exec'))"   
  6. install --record /tmp/pip-Urb3hW-record/install-record.txt --single-version-externally-managed --compile"   
  7. failed with error code 1 in /tmp/pip-build-OcAYDJ/mysql-python/  

在进行pip jinstall musql-python的时候就是出错!!!报错内容如上。


出错的原因是因为必须安装mysql-python包,从而安装此包:

[python]  view plain copy print ?
  1. [root@python ~]yum -y install mysql-devel  

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

[python]  view plain copy print ?
  1. [root@python ~]pip install mysql-python  
  2. Collecting mysql-python  
  3.   Using cached MySQL-python-1.2.5.zip  
  4. Installing collected packages: mysql-python  
  5.   Running setup.py install for mysql-python ... done  
  6. Successfully installed mysql-python-1.2.5  

成功安装。


在使用pip安装的模块的时候,如果需要卸载,那么只要pip uninstall packagename即可,还是蛮方便的。


此问题在2.7版本中发现,在2.6版本中仅仅需要安装mysql-python包即可导入。

[python]  view plain copy print ?
  1. [root@python ~]# python  
  2. Python 2.7.11 (default, Apr  5 201612:24:31)   
  3. [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2  
  4. Type "help""copyright""credits" or "license" for more information.  
  5. >>> import MySQLdb  
  6. >>>   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值