Python 安装requests和MySQLdb

2017年10月02日

0.系统版本

0.1 查看系统版本

 [root@localhost ~]# uname -a
 Linux localhost.localdomain -.el7.x86_64 # SMP Tue Nov  :: UTC  x86_64 x86_64 x86_64 GNU/Linux

1.安装requests

1.1 软件下载

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

1.2 解压

 [root@localhost ~]# .tar.gz 

1.3安装requests

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

1.4 安装报错

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

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

下载setuptools :

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

利用unzip进行解压

 [root@localhost requests-]# .zip 

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

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

解压完成后即可进行安装

 [root@localhost requests-]# cd setuptools-
 [root@localhost setuptools-]# python setup.py install

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

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

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

 [root@localhost requests-]# python
 Python  (default, Nov   , ::)
 [GCC   (Red Hat -)] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import requests
 >>> 

2.安装requests

2.1 软件下载

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

2.2 解压并且安装

 [root@localhost ~]# .zip
 [root@localhost ~]# cd MySQL-python-
 [root@localhost MySQL-python-]# python setup.py install

2.3 安装报错

 sh: mysql_config: not found
 Traceback (most recent call last):
   File , in <module>
     metadata, options = get_config()
   File , in get_config
     libs = mysql_config("libs_r")
   File , in mysql_config
     raise EnvironmentError("%s not found" % (mysql_config.path,))
 EnvironmentError: mysql_config not found

安装libmysqlclient-dev

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

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

 [root@localhost requests-]# 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-]# 

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

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

安装mariadb的dev包

 [root@localhost MySQL-python-]# 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-]# 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
  -fexceptions -fstack-protector-strong --param=ssp-buffer-size= -grecord- -fexceptions -fstack-protector-strong --param=ssp-buffer-size= -grecord-,,,) -D__version__= -I/usr/include/mysql -I/usr/include/python2. -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
 _mysql.c::: fatal error: Python.h: No such file or directory
  #include "Python.h"
                     ^
 compilation terminated.
 error: command 

再次安装python-devel

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

再次尝试

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

检测是否安装OK

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

安装requests和MySQLdb到此结束

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

Python 安装requests和MySQLdb的更多相关文章

  1. Python——安装requests第三方库

    使用pip安装 在cmd下cd到这个目录下C:\Python27\Scripts,然后执行pip install requests 在cmd 命令行执行 E:   进入e盘 cd  Python\pr ...

  2. python安装requests (win7 & centos7)

    下载地址: http://pypi.python.org/pypi/requests/只有tart.gz包 解压后,进入目录,安装命令: python setup.py install 会出现:Imp ...

  3. python安装requests

    下面是requests的安装步骤: 1.如果系统已经装了Python,把D:\python3.6.5\Scripts添加到系统的环境变量PATH后面 2.cmd下cd到这个目录下D:\Python3. ...

  4. Python 安装requests模块

    window下安装: 注:不要使用 easy_install requests 命令 这种方式安装后不能卸载,建议使用pip 方法 1.自动安装 输入cmd命令进入命令行窗口,执行 pip insta ...

  5. python安装requests第三方模块

    2018-08-28 22:04:51 1 .下载到桌面后解压,放到python的目录下 ------------------------------------------------------- ...

  6. 解决python本地离线安装requests问题

    使用python36进行本地requests安装的时候,由于安装requests需要联网,导致安装失败,现象如下: 一开始以为,需要安装什么证书,其实只是需要一个python的证书库,(⊙﹏⊙)b 执 ...

  7. python下载安装requests库

    一.python下载安装requests库 1.到git下载源码zip源码https://github.com/requests/requests 2.解压到python目录下: 3.“win+R”进 ...

  8. Python之Requests的安装与基本使用

    # 安装 使用 pip 安装Requests非常简单 pip install requests 或者使用 easy_install 安装 easy_install requests # 获得源码 Re ...

  9. python 安装插件 requests、BeautifulSoup

    安装第三方插件库 1. requests  , 下载地址 https://github.com/requests/requests 安装: 利用 pip 安装 pip3 install request ...

随机推荐

  1. centos7下Redis3的安装与使用

    redis是一个开源的,使用C语言编写的,支持网络交互的,可基于内存也可持久化的Key-Value数据库. 一.安装redis 下载redis源码 > wget http://download. ...

  2. Mysql: Specified key was too long; max key length is 1000 bytes

    在使用quartz持久化的时候,笔者使用的mysql,为了以后方便迁移数据,笔者的Mysql默认引擎MyISAM 于是顺理成章的执行了quartz-2.2.3\docs\dbTables\tables ...

  3. 在Qt(C++)中与Python混合编程

    一.PythonQt库 在Qt(C++)中与Python混合编程,可以使用PythonQt库. 网站首页:http://pythonqt.sourceforge.net 下载页面:https://so ...

  4. 用上了Godaddy的美国主机

    最近把两个域名转移到Godaddy上面后,就不停地收到它的促销邮件,送一些优惠码打折. 昨天通过它的优惠链接买了一个豪华型空间,支持无限空间,无限域名绑定. 看着邮件上写的是打半折,同时还免费送一个域 ...

  5. C++中的getline()

    总结: 尽量使用全局函数string类中的getline(),其读入的第二个参数为string类型,不设置默认是遇到回车停止读入操作 cin.getline是针对数组字符串的,以指定的地址为存放第一个 ...

  6. 案例情景--在一次Oracle 数据库导出时 EXP-00008;ORA-00904:EXP-00000: oracle不同版本导入导出规则

    案例情景--在一次Oracle 数据库导出时: C:\Documents and Settings\Administrator>exp lsxy/lsxy@lsxy_db file=E:\lsx ...

  7. java有车有房有能力最基本运用

    public class yunsuan { public static void main(String[] args) { // 1是有,0是没有 int i = 1, l = 0;// 有房 i ...

  8. php 多进程

    php 在使用场景中一般是处理web应用,所以多进程使用不适合在web中使用,且php-fpm中pcntl_fork不能使用,所以使用场景是在cgi模式下 一个进程调用pcntl_fork函数后,系统 ...

  9. JQuery Deferred 对象

    http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html <jQu ...

  10. MVC 第一章(下)

    继续第一章 用Javascript and jQuery调用Web API 在上一节,我们用浏览器直接调用web API.但是大多数web API被客户端应用以编程的方式调用.那么我们写一个简单的ja ...