kellyseeme

在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
>>> 



分类:

技术点:

相关文章:

  • 2021-05-26
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2021-11-29
  • 2021-06-11
  • 2021-12-15
  • 2022-12-23
猜你喜欢
  • 2022-03-15
  • 2021-11-16
  • 2022-12-23
  • 2021-11-29
  • 2022-01-19
  • 2021-08-28
  • 2021-08-10
相关资源
相似解决方案