感谢支持
我们一直在努力

Python 安装requests和MySQLdb

Python 安装requests和MySQLdb
0.系统版本

0.1 查看系统版本

1 [root@localhost ~]# uname -a
2 Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

1.安装requests

1.1 软件下载

1 [root@localhost ~]# wget \
2 https://pypi.python.org/packages/b0/e1/eab4fc3752e3d240468a8c0b284607899d2fbfb236a56b7377a329aa8d09/requests-2.18.4.tar.gz#md5=081412b2ef79bdc48229891af13f4d82

1.2 解压

1 [root@localhost ~]# tar xf requests-2.18.4.tar.gz 

1.3安装requests

1 [root@localhost ~]# cd requests-2.18.4
2 [root@localhost requests-2.18.4]# python setup.py install

1.4 安装报错

1 [root@1e supervisor-3.0]# python setup.py install  
2 Traceback (most recent call last):  
3   File "setup.py", line 31, in <module>  
4     from setuptools import setup, find_packages  
5 ImportError: No module named setuptools  

原因是没有找到setuptools包,再次安装这个包

下载setuptools :

1 [root@localhost requests-2.18.4]#wget \
2 https://pypi.python.org/packages/a4/c8/9a7a47f683d54d83f648d37c3e180317f80dc126a304c45dc6663246233a/setuptools-36.5.0.zip#md5=704f500dd55f4bd0be905444f3ba892c

利用unzip进行解压

1 [root@localhost requests-2.18.4]# unzip setuptools-36.5.0.zip 

如果提示没有找到unzip命令,则利用yum安装即可

1 [root@localhost requests-2.18.4]# yum install zip unzip 

解压完成后即可进行安装

1 [root@localhost requests-2.18.4]# cd setuptools-36.5.0
2 [root@localhost setuptools-36.5.0]# python setup.py install

安装完成后即可进行安装requests

1 [root@localhost setuptools-36.5.0]# cd ../
2 [root@localhost requests-2.18.4]# python setup.py install

 

安装完成检验,进入python交互式界面进行导入包即可

[root@localhost requests-2.18.4]# python
Python 2.7.5 (default, Nov  6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import requests
>>>

2.安装requests

2.1 软件下载

1 [root@localhost ~]# wget \
2 https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c

2.2 解压并且安装

1 [root@localhost ~]# unzip MySQL-python-1.2.5.zip 
2 [root@localhost ~]# cd MySQL-python-1.2.5
3 [root@localhost MySQL-python-1.2.5]# python setup.py install

2.3 安装报错

sh: mysql_config: not found
Traceback (most recent call last):
  File “setup.py”, line 15, in <module>
    metadata, options = get_config()
  File “/home/zhxia/apps/source/MySQL-python-1.2.3/setup_posix.py”, line 43, in get_config
    libs = mysql_config(“libs_r”)
  File “/home/zhxia/apps/source/MySQL-python-1.2.3/setup_posix.py”, line 24, in mysql_config
    raise EnvironmentError(“%s not found” % (mysql_config.path,))
EnvironmentError: mysql_config not found

安装libmysqlclient-dev

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

安装报错,并没有发现libmysqlclient-dev

[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可以索搜并且下载包

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-10/147880.htm

赞(0) 打赏
转载请注明出处:服务器评测 » Python 安装requests和MySQLdb
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏