美文网首页
centos--python3安装--django初始化

centos--python3安装--django初始化

作者: w_dll | 来源:发表于2020-01-09 21:00 被阅读0次

    1 centos7 下 python3的安装

    安装脚本如下

    #!/bin/bash
    yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel \
    readline-devel tk-devel gcc make gcc gcc-c++ autoconf libjpeg libjpeg-devel \
    libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib \
    zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses \
    ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn \
    libidn-devel openssl openssl-devel nss_ldap openldap openldap-devel \
    openldap-clients openldap-servers libxslt-devel libevent-devel \
    ntp libtool-ltdl bison libtool vim-enhanced pcre libffi-devel
    wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
    tar -xvf Python-3.8.0.tgz -C /usr/local
    mkdir /usr/local/python3;cd /usr/local/Python-3.8.0
    ./configure --prefix=/usr/local/python3
    make && make install
    ln -s /usr/local/python3/bin/python3 /usr/bin/python3
    ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
    

    如果在在官网上下载好Python-3.8.0.tgz文件
    链接:https://pan.baidu.com/s/1ShpZ6cIngDFluvqut1EIIw
    提取码:jpmv
    ,只需将wget那一行注释掉,将该文件和脚本放在同一文件夹下,执行脚本即可。

    2 安装虚拟环境以及Django

    安装pipenv

    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv
    

    创建并启动虚拟环境

    cd /home;mkdir project1 && cd project1
    python3 -m venv first_env
    . ./first_env/bin/activate
    

    安装django并指定版本
    下载慢解决方法

    pipenv install -i https://pypi.tuna.tsinghua.edu.cn/simple Django==2.2.3
    

    如图表示下载完成


    image.png

    3 创建项目

    pipenv run django-admin startproject blogproject
    

    4 修改配置

    修改语言

    cd ./blogproject/blogproject/
    cp settings.py settings.py~
    sed -i -e 's/en-us/zh-hans/' -e 's#UTC#Asia/Shanghai#' ./settings.py
    

    修改允许host

    sed -i "s/ALLOWED_HOSTS.*/ALLOWED_HOSTS = ['*']/" ./settings.py
    

    5 更改centos7默认sqlite3

    参考:
    https://blog.csdn.net/qq_39969226/article/details/92218635

    wget https://www.sqlite.org/2019/sqlite-autoconf-3270200.tar.gz
    tar -zxvf sqlite-autoconf-3270200.tar.gz
    mkdir /usr/sqlite3/
    cd sqlite-autoconf-3270200
    ./configure --prefix=/usr/sqlite3/
    make && make install
    mv /usr/bin/sqlite3  /usr/bin/sqlite3_old
    ln -s /usr/sqlite3/bin/sqlite3  /usr/bin/sqlite3
    cp ~/.bashrc ~/.bashrc_bak
    echo 'export LD_LIBRARY_PATH="/usr/sqlite3/lib"'>>~/.bashrc
    source ~/.bashrc
    

    相关文章

      网友评论

          本文标题:centos--python3安装--django初始化

          本文链接:https://www.haomeiwen.com/subject/dijyactx.html