解决 centerOS7部署ajango2.2.x版本 报SQLite 3.8.3 or later is required (found 3.7.17).错误

在CentOS7上部署Django的时候,遇到了一些问题,写篇笔记记录解决过程。

报错信息

python3 manage.py runserver启动django项目的时候,就会出现报错信息如下:
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).

这是因为centos 默认的版本为3.7.17,并没有更新,我们只需要安装新的SQLite代替老版本就可以了。可以去搜索sqlite官网去下载源码。

查看系统的sqlte3的版本

1 [root@djangoServer work]# sqlite3 --version 
2 3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
3 [root@djangoServer work]# 


Centos7安装最新的sqlite3并设置更新python库版本

 1 #更新SQLite 3
 2 #获取源代码(在主目录中运行)
 3 [root@djangoServer ~]# cd ~
 4 [root@djangoServer ~]# wget https://www.sqlite.org/2019/sqlite-autoconf-3270200.tar.gz
 5 [root@djangoServer ~]# tar -zxvf sqlite-autoconf-3270200.tar.gz
 6 
 7 #构建并安装
 8 [root@djangoServer ~]# cd sqlite-autoconf-3270200
 9 [root@djangoServer sqlite-autoconf-3270200]# ./configure --prefix=/usr/local
10 [root@djangoServer sqlite-autoconf-3270200]# make && make install
11 [root@djangoServer sqlite-autoconf-3270200]# find /usr/ -name sqlite3
12 /usr/bin/sqlite3
13 /usr/lib64/python2.7/sqlite3
14 /usr/local/bin/sqlite3
15 /usr/local/python3/lib/python3.7/site-packages/django/db/backends/sqlite3
16 /usr/local/python3/lib/python3.7/sqlite3
17 [root@djangoServer sqlite-autoconf-3270200]# 
18 
19 #不必要的文件,目录删除
20 [root@djangoServer sqlite-autoconf-3270200]# cd ~
21 [root@djangoServer ~]# ls
22 anaconda-ks.cfg  sqlite-autoconf-3270200  sqlite-autoconf-3270200.tar.gz
23 [root@djangoServer ~]# 
24 [root@djangoServer ~]# rm -rf sqlite-autoconf-3270200.tar.gz
25 [root@djangoServer ~]# rm -rf sqlite-autoconf-3270200
26 
27 #检查版本
28 ## 最新安装的sqlite3版本
29 [root@djangoServer ~]# /usr/local/bin/sqlite3 --version
30 3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
31 [root@djangoServer ~]# 
32 
33 ## Centos7自带的sqlite3版本
34 [root@djangoServer ~]# /usr/bin/sqlite3 --version
35 3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
36 [root@djangoServer ~]# 
37 
38 ## 可以看到sqlite3的版本还是旧版本,那么需要更新一下。
39 [root@djangoServer ~]# sqlite3 --version
40 3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
41 [root@djangoServer ~]# 
42 
43 ## 更改旧的sqlite3
44 [root@djangoServer ~]# mv /usr/bin/sqlite3  /usr/bin/sqlite3_old
45 
46 ## 软链接将新的sqlite3设置到/usr/bin目录下
47 [root@djangoServer ~]# ln -s /usr/local/bin/sqlite3   /usr/bin/sqlite3
48 
49 ## 查看当前全局sqlite3的版本
50 [root@djangoServer ~]# sqlite3 --version
51 3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
52 [root@djangoServer ~]# 
53 
54 #将路径传递给共享库
55 # 设置开机自启动执行,可以将下面的export语句写入 ~/.bashrc 文件中,如果如果你想立即生效,可以执行source 〜/.bashrc 将在每次启动终端时执行
56 [root@djangoServer ~]# export LD_LIBRARY_PATH="/usr/local/lib"
57 
58 #检查Python的SQLite3版本
59 [root@djangoServer ~]# ipython3
60 Python 3.6.8 (default, Aug  7 2019, 17:28:10) 
61 [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
62 Type "help", "copyright", "credits" or "license" for more information.
63 >>> import sqlite3
64 >>> sqlite3.sqlite_version   
65 '3.27.2'
66 >>> exit()                                                            
67 [root@djangoServer ~]# 
68 
69 #启动开发服务器
70 [root@djangoServer ~]# cd /work/
71 [root@djangoServer work]# ls
72 db.sqlite3  manage.py  polls  test_django
73 [root@djangoServer work]# python3 manage.py runserver
74 Watching for file changes with StatReloader
75 Performing system checks...
76 
77 System check identified no issues (0 silenced).
78 May 03, 2019 - 21:32:28
79 Django version 2.2.1, using settings 'test_django.settings'
80 Starting development server at http://127.0.0.1:8000/
81 Quit the server with CONTROL-C.

猜你喜欢

转载自www.cnblogs.com/iverson-3/p/12381788.html