Centos7 安装启动Django

一、安装Python3

  1. 依赖
    yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
    yum install gcc -y

  2. 安装python
    wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
    mv Python-3.7.4.tgz /usr/local/
    mkdir /usr/local/python3
    cd /usr/local/
    tar -xvf Python-3.7.4.tgz
    cd /usr/local/Python-3.7.4/
    ./configure --prefix=/usr/local/python3
    make && make install

    ModuleNotFoundError: No module named '_ctypes',这是因为缺少依赖包libffi-devel,解决方法可参考https://blog.csdn.net/CUFEECR/article/details/103093951

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

  1. 安装pip3
    yum install openssl-devel -y
    yum install zlib-devel -y
    wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
    tar -zxvf setuptools-19.6.tar.gz
    cd setuptools-19.6
    sudo python3 setup.py build
    sudo python3 setup.py install
    export PATH=$PATH:/usr/local/python3/bin

安装Django

  1. 设置源
    pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
  2. 安装
    pip3 install Django
  3. 创建项目
    django-admin startproject App1
    python3 manage.py runserver
    参考https://docs.djangoproject.com/zh-hans/4.0/intro/tutorial01/

异常:django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17).
解决:更新sqlite
cd /usr/local/src
wget http://www.sqlite.org/2021/sqlite-autoconf-3360000.tar.gz
tar -zxvf sqlite-autoconf-3360000.tar.gz
cd sqlite-autoconf-3360000
./configure --prefix=/usr/local/sqlite
make && make install
mv /usr/bin/sqlite3 /usr/bin/sqlite3_bak
cd /usr/local/sqlite/bin/
ln -s sqlite3 /usr/bin/sqlite3
vim /etc/profile
export LD_LIBRARY_PATH="/usr/local/sqlite/lib"
source /etc/profile
import sqlite3
sqlite3.sqlite_version
如果异常:django.db.utils.NotSupportedError: deterministic=True requires SQLite
pip3 install pysqlite3
pip3 install pysqlite3-binary
vim /usr/local/python3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py
from sqlite3 import dbapi2 as Database (注释掉这段)
from pysqlite3 import dbapi2 as Database #改成pysqlite3

你可能感兴趣的:(Centos7 安装启动Django)