报错(SQLite 3.8.3 or later is required (found 3.7.17).)的解决办法

在服务器上刚部署完Django项目,python manage.py runserver 0.0.0.0:8000启动启动的时候报错:django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).,以下为报错展示及解决办法。

目录

    • 一、报错演示
    • 二、问题解决

一、报错演示

(venv) [root@localhost celery]# python manage.py  runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/local/python3/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/python3/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/celery/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/home/celery/venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/home/celery/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
    raise _exception[1]
  File "/home/celery/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
    autoreload.check_errors(django.setup)()
  File "/home/celery/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/home/celery/venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/celery/venv/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/home/celery/venv/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/celery/venv/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 665, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 219, in _call_with_frames_removed
  File "/home/celery/venv/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/home/celery/venv/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
  File "/home/celery/venv/lib/python3.6/site-packages/django/db/models/base.py", line 121, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/home/celery/venv/lib/python3.6/site-packages/django/db/models/base.py", line 325, in add_to_class
    value.contribute_to_class(cls, name)
  File "/home/celery/venv/lib/python3.6/site-packages/django/db/models/options.py", line 208, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/home/celery/venv/lib/python3.6/site-packages/django/db/__init__.py", line 28, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/home/celery/venv/lib/python3.6/site-packages/django/db/utils.py", line 207, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/home/celery/venv/lib/python3.6/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/home/celery/venv/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/celery/venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 68, in <module>
    check_sqlite_version()
  File "/home/celery/venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 65, in check_sqlite_version
    raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).

二、问题解决

  1. 按照习惯,翻译一下报错信息
    在这里插入图片描述
    大致意思是:Django需要SQLite 3.8.3或更高版本,而现在的版本为3.7.17

  2. 两个解决办法
    方法一:给Django降级

    如果是生产环境或者项目规定了Django版本,那么降级Django会引起一系列的问题,本人建议使用方法二,慎重慎重,当然测试环境就无所谓了。

    卸载Django

    pip uninstall django
    

    安装低版本,版本号根据自身项目选择合适的

    pip install django==2.1.7
    

    方法二:升级SQLite
    (1)获取安装包下载链接
    下载地址:https://www.sqlite.org/download.html
    报错(SQLite 3.8.3 or later is required (found 3.7.17).)的解决办法_第1张图片

    最好重新获取一下下载链接,否则可能不是最新版(以上截图为本人写此篇文章时候的最新版)

    (2)wget下载

    #链接最好重新获取,否则可能不是最新版本
    wget https://www.sqlite.org/2019/sqlite-autoconf-3300100.tar.gz
    

    (3)解压并安装

    [root@localhost home]# tar zxvf sqlite-autoconf-3300100.tar.gz
    [root@localhost home]# cd sqlite-autoconf-3300100/
    [root@localhost sqlite-autoconf-3300100]# ./configure
    [root@localhost sqlite-autoconf-3300100]# make & make install
    

    (4)查看版本

    #检查新安装的sqlite3版本
    [root@localhost home]# /usr/local/bin/sqlite3 --version
    3.30.1 2019-10-10 20:19:45 18db032d058f1436ce3dea84081f4ee5a0f2259ad97301d43c426bc7f3df1b0b
    
    #检查旧的sqlite3版本
    [root@localhost home]# /usr/bin/sqlite3 --version
    3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
    
    # 把旧的sqlite3改个名字
    [root@localhost home]# mv /usr/bin/sqlite3  /usr/bin/sqlite3_old
    
    # 设置软链接
    [root@localhost home]# ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
    
    #查看sqlite3版本
    [root@localhost home]# sqlite3 --version
    3.30.1 2019-10-10 20:19:45 18db032d058f1436ce3dea84081f4ee5a0f2259ad97301d43c426bc7f3df1b0b
    

    (5)设置开机自启动

    # 设置开机自启动
    [root@localhost home]# export LD_LIBRARY_PATH="/usr/local/lib"
    

    (6)检查Python的SQLite3版本

    [root@localhost home]# python3
    Python 3.6.5 (default, Jul  9 2019, 20:03:55) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sqlite3
    >>> sqlite3.sqlite_version
    '3.30.1'
    >>> exit()  
    [root@localhost home]# 
    

    (7)完成

如果你使用虚拟环境启动的项目,可能还会继续报错,需要把虚拟环境删除,重新创建即可
友情提示:可以先生成依赖文件,然后一会批量导入。
可能用到的命令

  1. 依赖文件生成:pip freeze > requirements.txt
  2. 依赖文件安装:pip install -r requirements.txt
  3. 创建虚拟环境(不指定Python版本,Centos7默认会使用2.7):virtualenv name
  4. 创建虚拟环境(指定Python版本):virtualenv -p /usr/bin/python3 name

欢迎留言吐槽

你可能感兴趣的:(报错笔记)