背景
Python在写一些简单存储的小应用时,一般采用文本存储或者sqlite3就可以了,但是一旦需要遇到大量数据的存储和查询的时候,使用文本和sqlite3就显得力不从心了,存储查询的速度明显变慢,这个时候可以选择使用mysql数据库来存储,Linux下面安装MySQL-python可能会遇到这些问题。
Ubuntu16.04下面安装MySQL-python模块的方法很简单,使用apt-get 或者 pip都可以快速安装完成,执行以下命令
apt-get install python-mysqldb 或者 pip install mysql-python
但是CentOS下面可能就会出现问题。
CentOS
CentOS 7 下面使用yum是找不到MySQL-python这个东西的,推荐使用pip安装,执行以下命令安装这个模块
pip install mysql-python
但是安装并没有这么顺利,出现如下错误
Collecting mysql-python Using cached MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: sh: mysql_config: 未找到命令 Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-build-w_VWdz/mysql-python/setup.py", line 17, in <module>meta data, options = get_config() File "setup_posix.py", line 43, in get_config libs = mysql_config("libs_r") File "setup_posix.py", line 25, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-w_VWdz/mysql-python/
解决
根据互联网搜索的结果来看,有前辈已经给出了解决方法,就是需要安装一些软件包的dev版本,安装如下软件包
yum install python-devel mysql-devel zlib-devel openssl-devel
安装完成之后再执行上面的pip安装即可
Collecting MySQL-python Using cached MySQL-python-1.2.5.zip Building wheels for collected packages: MySQL-python Running setup.py bdist_wheel for MySQL-python ... done Stored in directory: /root/.cache/pip/wheels/38/a3/89/ec87e092cfb38450fc91a62562055231deb0049a029054dc62 Successfully built MySQL-python Installing collected packages: MySQL-python Successfully installed MySQL-python-1.2.5
参考
https://www.sunnyos.com/article-show-38.html
如果您觉得文章有帮助到您,请到 http://www.92ez.com/index.php?action=show&id=23403 进行打赏/捐赠,谢谢!
本文链接:http://www.92ez.com/?action=show&id=23431