Python 安装requests和MySQLdb(2)

[root@localhost requests-2.18.4]# yum install libmysqlclient-dev
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sohu.com
 * extras: mirrors.sohu.com
 * updates: mirrors.sohu.com
No package libmysqlclient-dev available.
Error: Nothing to do
[root@localhost requests-2.18.4]#

之所以会出现如下原因是系统没有找到mysql的依赖包,那么我们可以自己安装依赖,这儿依赖可以为mysql 也可以为mariadb

[root@localhost MySQL-python-1.2.5]# yum list all | grep mariadb | grep dev
mariadb-devel.x86_64                        1:5.5.56-2.el7            @base   
mariadb-embedded-devel.x86_64              1:5.5.56-2.el7            @base   
mariadb-devel.i686                          1:5.5.56-2.el7            base   
mariadb-embedded-devel.i686                1:5.5.56-2.el7            base   
[root@localhost MySQL-python-1.2.5]#
 

安装mariadbdev

1 [root@localhost MySQL-python-1.2.5]# yum install mariadb-devel mariadb-embedded-devel

再次安装MySQL-python-1.2.5

[root@localhost MySQL-python-1.2.5]# python setup.py install

再次报错

[root@localhost MySQL-python-1.2.5]# python setup.py install
running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
reading manifest file 'MySQL_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MySQL_python.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
_mysql.c:29:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1

再次安装python-devel

1 [root@localhost MySQL-python-1.2.5]# yum install python-devel

再次尝试

1 [root@localhost MySQL-python-1.2.5]# python setup.py install

检测是否安装OK

[root@localhost MySQL-python-1.2.5]# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.pyc, but /root/python-script/MySQL-python-1.2.5 is being added to sys.path
>>>

安装requestsMySQLdb到此结束

关于python包的下载:https://pypi.python.org/pypi可以索搜并且下载包

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/13336.html