zoukankan      html  css  js  c++  java
  • Django学习排错备注

    一、ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3

      学习Django第五章的模型的时候,图省事,用了sqlite,当时修改完settings.py时,用python manage.py shell启动时,却报如上所示错误。

      平台环境:Centos 5.8, python 2.7.4,django 1.5.1

      解决步骤

      1、google搜索半天,发现不是django配置的问题,而是python的环境问题,有人说是sqlite-devel没有装,要安装后reinstall python,于是yum -y install sqlite-devel后想重装python

    但是make的时候发现build sqlite3时报错:Failed to build these modules: _sqlite3

    无奈又上网搜索,在强大的stackoverflow里看到了一个解决方法,原来这是python 2.7.x的bug,在这里(http://bugs.python.org/issue14572)发布了补丁,

    先cd到python的源码解压后的目录,执行curl -sk https://raw.github.com/gist/2727063/ | patch -p1,然后重新make,结果还是报同样的错误,又无语了。

    后来在网上搜索的时候发现了一个脚本,这个脚本作用是安装python2.7.2的,也可以修改里面的参数,用于安装其他版本!

    脚本下载地址找不到了,附上内容吧

    View Code
    #!/bin/bash
    # v0.0.1
    # Compile Python 2.7.2 from scratch 
    # Tested on Centos 5.8
    CURR_DIR=/usr/local
    SRCDIR="$CURR_DIR/src"
    BUILDDIR="$CURR_DIR/build"
    
    # Create Source Directories
    if [ ! -d "$SRCDIR" ]
    then
        mkdir -pv $SRCDIR
    fi
    
    if [ ! -d "BUILDDIR" ]
    then
        mkdir -pv $BUILDDIR
    fi
    
    
    pybuild_remove() {
        echo Removing all set ENV Vars
        unset PREFIX CFLAGS CPPFLAGS LDFLAGS LD_RUN_PATH C_INCLUDE_PATH
        unset CPLUS_INCLUDE_PATH
    }
    
    pybuild_add() {
        echo Adding default ENV Vars
        export PREFIX="/usr/local/python2.7.2"
        export C_INCLUDE_PATH="$PREFIX/include"
        export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH
        export LIBRARY_PATH="$PREFIX/lib"
        export LD_RUN_PATH="$PREFIX/lib"
    }
    
    pybuild_add_prepython() {
        echo Adding pre Python build includes
        export C_INCLUDE_PATH="$PREFIX/include/ncurses:$PREFIX/include/readline:$PREFIX/include/openssl:$C_INCLUDE_PATH"
        export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH"
    }
    
    build_cleanup() {
        echo cleaning up $BUILDDIR
        cd $BUILDDIR
        rm -rf $BUILDDIR/*
    }
    
    dl_if_none() {
        # takes 2 parameters
        # $1 - filename
        # $2 - url
        echo Downloading source file
        if [ -e "$SRCDIR/$1" ]
        then
            echo Source file $1 already exists
        else
            wget $2 -O "$SRCDIR/$1"
        fi
    }
    
    pybuild_sqlite3() {
        dl_if_none sqlite-autoconf-3071000.tar.gz http://www.sqlite.org/sqlite-autoconf-3071000.tar.gz
        tar -C $BUILDDIR -zxf $SRCDIR/sqlite*
        cd $BUILDDIR/sqlite*
        pybuild_add
        ./configure --prefix=$PREFIX
        make
        make install
        pybuild_remove
        build_cleanup
    }
    
    
    pybuild_bzip2() {
        dl_if_none bzip2-1.0.6.tar.gz http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
        tar -C $BUILDDIR -zxf $SRCDIR/bzip2*
        cd $BUILDDIR/bzip2*
        pybuild_add
        make -f Makefile-*
        make install PREFIX=$PREFIX
        make
        make install PREFIX=$PREFIX
        pybuild_remove
        build_cleanup
    }
    
    
    pybuild_zlib() {
        dl_if_none zlib-1.2.5.tar.gz http://zlib.net/zlib-1.2.5.tar.gz
        tar -C $BUILDDIR -zxf $SRCDIR/zlib*
        cd $BUILDDIR/zlib*
        pybuild_add
        ./configure --prefix=$PREFIX
        make
        make install
        pybuild_remove
        build_cleanup
    }
    
    
    pybuild_openssl() {
        dl_if_none openssl-1.0.0g.tar.gz http://www.openssl.org/source/openssl-1.0.0g.tar.gz
        tar -C $BUILDDIR -zxf $SRCDIR/openssl*
        cd $BUILDDIR/openssl*
        pybuild_add
        ./config --prefix=$PREFIX -I$PREFIX/include -L$PREFIX/lib threads shared --openssldir=$PREFIX/openssl zlib
        make
        make install
        pybuild_remove
        build_cleanup
    }
    
    pybuild_ncurses() {
        dl_if_none ncurses-5.9.tar.gz http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz
        tar -C $BUILDDIR -zxf $SRCDIR/ncurses*
        cd $BUILDDIR/ncurses*
        pybuild_add
        ./configure --with-normal --with-shared --prefix=$PREFIX --enable-rpath --enable-sp-funcs --enable-const --enable--ext-mouse
        make
        make install
        pybuild_remove
        build_cleanup
    }
    
    pybuild_readline() {
        dl_if_none readline-6.2.tar.gz ftp://ftp.gnu.org/gnu/readline/readline-6.2.tar.gz
        tar -C $BUILDDIR -zxf $SRCDIR/readline*
        cd $BUILDDIR/readline*
        pybuild_add
        ./configure --prefix=$PREFIX 
        make
        make install
        pybuild_remove
        build_cleanup
    }
    
    pybuild_gdbm() {
        dl_if_none gdbm-1.10.tar.gz ftp://ftp.gnu.org/gnu/gdbm/gdbm-1.10.tar.gz
        tar -C $BUILDDIR -zxf $SRCDIR/gdbm*
        cd $BUILDDIR/gdbm*
        pybuild_add
        ./configure --prefix=$PREFIX 
        make
        make install
        pybuild_remove
        build_cleanup
    }
    
    pybuild_bsdbm() {
        dl_if_none db-4.3.29.tar.gz http://download.oracle.com/berkeley-db/db-4.3.29.tar.gz
        tar -C $BUILDDIR -zxf $SRCDIR/db*
        cd $BUILDDIR/db-*/build_unix
        pybuild_add
        ../dist/configure --prefix=$PREFIX
        make
        make install
        pybuild_remove
        build_cleanup
    }
    
    pybuild_python() {
        dl_if_none Python-2.7.2.tar.bz2 http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
        tar -C $BUILDDIR -jxf $SRCDIR/Python*
        cd $BUILDDIR/Python*
        pybuild_add
        pybuild_add_prepython
        ./configure --enable-shared --prefix=$PREFIX --enable-ipv6  --with-dbmlib
    order=gdbm:bdb --with-threads
        make
        make install
        pybuild_remove
        build_cleanup
    }
    
    build_python27() {
        pybuild_remove
        pybuild_sqlite3
        pybuild_bzip2
        pybuild_zlib
        pybuild_openssl
        pybuild_ncurses
        pybuild_readline
        pybuild_gdbm
        pybuild_bsdbm
        pybuild_python
    }
    
    build_python27

    重点在pybuild_sqlite3函数,原来我是因为sqlite没有装好,利用编译安装sqlite的方式后就解决这个问题了!

    ------ 若讷于言,则敏于行!------
  • 相关阅读:
    线程概念简介 什么是线程 多线程上篇(七)
    进程通信概念简介 多线程上篇(六)
    进程同步经典示例 多线程上篇(五)
    进程同步概念简介 多线程上篇(四)
    进程控制概念简介 多线程上篇(三)
    进行概念详解 多线程上篇(二)
    操作系统与程序运行以及进程简介 多线程上篇(一)
    Mybatis动态SQL简单了解 Mybatis简介(四)
    Mybatis sql映射文件浅析 Mybatis简介(三)
    Mybatis配置信息浅析 MyBatis简介(二)
  • 原文地址:https://www.cnblogs.com/searchappiness/p/3064044.html
Copyright © 2011-2022 走看看