zoukankan      html  css  js  c++  java
  • centos6.3环境下升级python及MySQLdb的安装

      近来突然想鼓捣下linux下的python,看下Python数据库方面的东西,想着在centos下测试下。然而安装的过程有很多坑。下面对整个流程进行下记录

    1、python基本库的安装

         在安装python的过程中,发现其中很多的依赖库是没有包含在内的。根据我的需要,我安装了sqlite和zlib这两个依赖库。具体过程说明如下:

    (1)sqlite

    1>下载文件sqlite-autoconf-3160100.tar.gz:

        http://pan.baidu.com/s/1slOw8BN

    2>解压

    3>配置、编译、安装

    ./configure
    make
    make install

    需要注意的是,configure这里一定要用默认路径。否则后面很多地方会需要额外配置(而且我不知道怎么配置...)。

    (2)zlib

    1>下载文件zlib-1.2.7.tar.gz:

        http://pan.baidu.com/s/1o77r12M

    2>解压

    3>配置、编译、安装

    ./configure
    make
    make install

    2、python安装

    到这里开始进入正题了。

    其实centos6.3中是有python的,但版本是2.6.6的。虽然并没有什么用,我还是想升级一下...

    (1)下载python的源文件Python-2.7.13.tgz:

        http://pan.baidu.com/s/1c1YGnhI

    (2)解压

    (3)配置

    ./configure --prefix=/usr/local --with-libs='/usr/local/include/zconf.h'

        为了保险,我加了个zlib的路径

    (4)更改源文件文件夹中的setup文件

        Python-2.7.13->Modules->Setup,找到

    #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz,去掉前面的注释#

    (5)配置、编译、安装(为了保险,再配置一次)

    ./configure --prefix=/usr/local --with-libs='/usr/local/include/zconf.h'
    make
    make install

     (6)设定软链接

         在这一步,将python命令由原来系统默认的python2.6.6改置我们新安装的python2.7.13,将python2.6.6的软连接重命名为python2.6

    mv /usr/bin/python /usr/bin/python2.6
    ln -s /usr/local/bin/python2.7 /usr/bin/python

    (7)将yum的执行重定向置python2.6.6

        需要注意的是,yum命令是不兼容python2.7的,所以需要重新指定yum的python版本至python2.7。

    #vim /usr/bin/yum

    将文件头部的

    #!/usr/bin/python

    改成

    #!/usr/bin/python2.6

        

    3、安装setuptools

    (1)下载setuptools-0.6c11-py2.7.egg:

        http://pan.baidu.com/s/1c116neS

    (2)安装

    sh setuptools-0.6c11-py2.7.egg

    4、安装mysql_config

        在后面安装mysql-python的操作中会发现报错EnvironmentError:mysql_config not found,解决方案如下:

    sudo yum install libmysqlclient-dev
    sudo yum install python-devel

        这样,文件mysql_config就已经被安装好了。下面找一下它的路径

    find / -name mysql_config

        shell将返回mysql_config的地址

    /usr/lib/mysql/mysql_config
    /usr/bin/mysql_config

        我们认为有效地址是/usr/bin/mysql_config(我也不知道为啥...)

    5、安装MySQL-python

    (1)下载文件MySQL-python-1.2.3.tar.gz:

        http://pan.baidu.com/s/1i471Ltz

    (2)解压&进行一些必要更改

        下面更改MySQL-python-1.2.3目录下面的site.cfg文件:

        去掉mysql_config=XXX这行的注释,并改成:

    mysql_config=/usr/bin/mysql_config

     (3)编译&安装

    cd MySQL-python-1.2.3
    python setup.py build
    python setup.py install

    至此搞定!

    参考来源:

    [1]对于python编译过程中依赖库报错的说明:http://www.tuicool.com/articles/FjmA3u

    [2]centos编译安装zlib:http://lbs1991.blog.51cto.com/9134853/1566891

    [3]centos编译安装zlib:http://blog.csdn.net/zhouzhiwengang/article/details/51675002

    [4]对linux软链接、硬链接的讲解:http://www.cnblogs.com/wancy86/p/linux_inode.html

    [5]对python升级的比较好的讲解:http://www.91pen.net/centos6-5-upgrade-python-2-6-to-2-7.html

    [6]报错EnvironmentError:mysql_config not found的解决方案:http://codingnow.cn/language/159.html

    [6]报错EnvironmentError:mysql_config not found的解决方案:http://www.cnblogs.com/xiazh/archive/2012/12/12/2814289.html

  • 相关阅读:
    bzoj 3732: Network 树上两点边权最值
    思维题题集--------一直都很害怕这些题
    Regionals 2014 >> Asia
    小小粉丝度度熊 二分答案 + two pointer
    I
    Binary Strings Gym
    卸载虚拟机时错误关闭了某个服务,使得电脑除了chrome浏览器都不能联网
    双系统给ubuntu增加分区
    tomcat问题
    eclipse:报错信息The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
  • 原文地址:https://www.cnblogs.com/funbing/p/6254104.html
Copyright © 2011-2022 走看看