Centos6.7下安装python连接mysql环境故障解决

前端之家收集整理的这篇文章主要介绍了Centos6.7下安装python连接mysql环境故障解决前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在Python连接和使用MysqL时,需要调用MysqLdb 模块,是用于Python链接MysqL数据库的接口,它实现了 Python 数据库 API 规范 V2.0,基于 MysqL C API 上建立的。

MysqLdb模块在不同的平台下安装方式不一样,这里主要介绍Linux下的安装方式,https://pypi.python.org/pypi/MySQL-python 可以在这里选择合适的版本,解压安装。

安装步骤:

1、选择合适的版本以及检查相关路径
这里选择版本为MysqL-python-1.2.5.zip,下面是下载路径与过程。
wgethttps://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MysqL-python-1.2.5.zip
--2016-10-0821:34:56--https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MysqL-python-1.2.5.zip
Resolvingpypi.python.org...151.101.76.223,2a04:4e42:12::223
Connectingtopypi.python.org|151.101.76.223|:443...connected.
HTTPrequestsent,awaitingresponse...200OK
Length:108935(106K)[application/octet-stream]
Savingto:“MysqL-python-1.2.5.zip”

100%[======================================================>]108,935--.-K/sin0.1s

2016-10-0821:34:57(1.00MB/s)-“MysqL-python-1.2.5.zip”saved[108935/108935]

[root@localhostpython]#ls
MysqL.pyMysqL-python-1.2.5.zip
解压:
[root@localhostpython]#unzipMysqL-python-1.2.5.zip
Archive:MysqL-python-1.2.5.zip
inflating:MysqL-python-1.2.5/GPL-2.0
inflating:MysqL-python-1.2.5/HISTORY
inflating:MysqL-python-1.2.5/INSTALL
inflating:MysqL-python-1.2.5/MANIFEST.in
inflating:MysqL-python-1.2.5/Metadata.cfg
inflating:MysqL-python-1.2.5/PKG-INFO
inflating:MysqL-python-1.2.5/pymemcompat.h
inflating:MysqL-python-1.2.5/README.md
inflating:MysqL-python-1.2.5/setup.cfg
inflating:MysqL-python-1.2.5/setup.py
inflating:MysqL-python-1.2.5/setup_common.py
inflating:MysqL-python-1.2.5/
切换到解压目录安装:
使用命令pythonsetup.pybuild&&pythonsetup.pyinstall

安装报错:

[root@localhostMysqL-python-1.2.5]#pythonsetup.pybuild
Traceback(mostrecentcalllast):
File"setup.py",line7,in<module>
importsetuptools
ImportError:Nomodulenamedsetuptools
提示缺少setuptools可以在


安装命令和上面一样,等最后执行完毕没有报错,安装成功,我们继续安装上面的。
pythonsetup.pybuild
runningbuild
runningbuild_py
creatingbuild
creatingbuild/lib
copyingpkg_resources.py->build/lib
copyingeasy_install.py->build/lib
copyingsite.py->build/lib
creatingbuild/lib/setuptools
copyingsetuptools/package_index.py->build/lib/setuptools
copyingsetuptools/depends.py->build/lib/setuptools
copyingsetuptools/extension.py->build/lib/setuptools
copyingsetuptools/__init__.py->build/lib/set
。。。。。。

Installed/usr/local/python2.7.11/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processingdependenciesforsetuptools==0.6c11
Finishedprocessingdependenciesforsetuptools==0.6c11
[root@localhostsetuptools-0.6c11]#cd..

继续安装MysqL-python出现error:command'gcc'Failedwithexitstatus1可以用以下命令解决

yuminstallgccpython-develMysqL-devellibxml2libxml2-devlibxslt*zlibgccopenssl

安装完成后的检验:

在shell窗口调用Python命令,然后执行,不报错即可

importMysqLdb

猜你在找的CentOS相关文章