15

In a virtual Env with Python 3.7.2, I am trying to run django's python manage.py startap myapp and I get this error:

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.8.2).

I'm running Ubuntu Trusty 14.04 Server.

How do I upgrade or update my sqlite version to >=3.8.3?

I ran

$ apt list --installed | grep sqlite

libaprutil1-dbd-sqlite3/trusty,now 1.5.3-1 amd64 [installed,automatic]
libdbd-sqlite3/trusty,now 0.9.0-2ubuntu2 amd64 [installed]
libsqlite3-0/trusty-updates,trusty-security,now 3.8.2-1ubuntu2.2 amd64 [installed]
libsqlite3-dev/trusty-updates,trusty-security,now 3.8.2-1ubuntu2.2 amd64 [installed]
python-pysqlite2/trusty,now 2.6.3-3 amd64 [installed]
python-pysqlite2-dbg/trusty,now 2.6.3-3 amd64 [installed]
sqlite3/trusty-updates,trusty-security,now 3.8.2-1ubuntu2.2 amd64 [installed]

and

sudo apt install --only-upgrade libsqlite3-0

Reading package lists... Done
Building dependency tree      
Reading state information... Done
libsqlite3-0 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 14 not upgraded.

EDIT: the settings.py is stock standard:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
Chubeez
  • 191
  • 1
  • 1
  • 6
  • It is not easy as Ubuntu 14.04 comes with SQLite 3.8.2 and there is no updated package. See https://askubuntu.com/questions/580355/sqlite-3-8-3-version-on-ubuntu-14-04 – Selcuk Apr 04 '19 at 06:21
  • can show your settings.py configuration for database – rahul.m Apr 04 '19 at 06:59
  • 1
    Compile it from source yourself and see if Python picks up a newer version in `/usr/local/` instead of the system one? – Shawn Apr 04 '19 at 10:48

5 Answers5

16

If you don't want to recompile Python and you're using a virtualenv you can do this to set it up without affecting the system as a whole (I've done this with Ubuntu 16/18):

  1. Download SQLite tarball from https://www.sqlite.org/download.html

  2. Extract the contents and cd into the folder.

  3. Run the following commands:

    ./configure

    sudo make install

  4. Now edit the activate script used to start your virtualenv so Python looks in the right place for the newly installed SQLite. Add the following line to the top of /path/to/virtualenv/bin/activate:

    export LD_LIBRARY_PATH="/usr/local/lib"

Now, when active, Django 2.2+ should work fine in the virtualenv. Hope that helps.

PyUnchained
  • 560
  • 1
  • 7
  • 16
  • Saved my time, this works for django-oscar when run: `make sandbox` – Rufat Apr 26 '20 at 13:33
  • 1
    can confirm, this worked on CentOS 7 / sqlite 3.31. did the configure/make as root and the export in the virtualenv. – uncovery May 08 '20 at 08:39
  • by active script, you are referring to the `.bashrc` file? – Shmack Feb 25 '21 at 06:31
  • doing that throws the error: `django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher` – Shmack Feb 25 '21 at 06:40
  • @ShanerM13 By activation script, I mean the script ./bin/activate that you use to start the turn on the virtualenv. – PyUnchained Feb 25 '21 at 23:14
  • If thats the case, why could I just not create a new virtual environment? Would it not look at the updated SQLite if a new one was created? I am testing all this now, just typing it out as well :) – Shmack Feb 26 '21 at 03:16
  • 1
    @ShanerM13 Interesting. Looked into it and it seems Ubuntu ships with a specific version of sqlite that it uses internally, located in '/usr/bin/'. If you simply create a new virtualenv it will still use the default one, not the newly installed one in '/usr/bin/local' unless you explicitly export the new path. – PyUnchained Feb 26 '21 at 23:42
  • Ummm... so you are suggesting that I use `export LD_LIBRARY_PATH=usr/bin/local` as opposed to `export LD_LIBRARY_PATH=/usr/local/lib`? I actually opened a thread on SO based on this error (https://stackoverflow.com/questions/66380006/django-deterministic-true-requires-sqlite-3-8-3-or-higher-upon-running-python/66380909#66380909) – Shmack Feb 27 '21 at 06:52
  • `export LD_LIBRARY_PATH="/usr/local/lib"` did the trick for me. – ospider Apr 12 '21 at 03:43
8

I've just been through this. I had to install a separate newer version of SQLite, from

https://www.sqlite.org/download.html

That is in /usr/local/bin. Then I had to recompile Python, telling it to look there:

sudo LD_RUN_PATH=/usr/local/lib ./configure --enable-optimizations
sudo LD_RUN_PATH=/usr/local/lib make altinstall

To check which version of SQLite Python is using:

$ python
Python 3.7.3 (default, Apr 12 2019, 16:23:13) 
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.27.2'
Mark Bailey
  • 1,617
  • 1
  • 7
  • 13
  • I'm also facing this problem, however running CentOS 7 and Python 3.6. I managed to install SQLite 3.28 from http://www.linuxfromscratch.org/blfs/view/svn/server/sqlite.html and running `sqlite3 --version` from the command line returns the correct version, however Python is still using SQLite 3.7.x. How do I go about recompiling Python? – camslice May 20 '19 at 17:27
  • Just followed the instructions here to compile Python from source: https://www.code-learner.com/how-to-compile-and-install-python3-from-source-code-in-centos/ Can confirm this works on CentOS 7.6.1810 with Python 3.7.2 and SQLite 3.28.0 – camslice May 20 '19 at 17:42
8

This error comes because your virtual environment could not connect to newly updated sqlite3 database. For that you have to update your sqlite3 database version manually and then give path of it to your virtual environment. Kindly follow below steps:

  1. Download latest sqlite3 from official site. (https://www.sqlite.org/download.html)wget http://www.sqlite.org/sqlite-autoconf-3070603.tar.gz

  2. Then go to that folder and fire command. tar xvfz sqlite-autoconf-3070603.tar.gz

  3. Go to respective folder. cd sqlite-autoconf-3070603

  4. ./configure

  5. make

  6. make install It may take too time but wait till end. If it's take too much then terminate that process and continue rest of steps.

  7. Now you successfully install updated sqlite3. Now fire this command sudo LD_RUN_PATH=/usr/local/lib ./configure --enable-optimizations

  8. Open your activate file of virtual environment (e.g., venv/bin/activate) and add this line top of the file... export LD_LIBRARY_PATH="/usr/local/lib"

  9. Now for checking you can type this commands to your python shell

$ python
Python 3.7.3 (default, Apr 12 2019, 16:23:13) 
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.27.2'
Parth Ghinaiya
  • 119
  • 2
  • 6
  • 2
    I have warning "configure: WARNING: unrecognized options: --enable-optimizations". Where is "--enable-optimizations" from? – Gqqnbig Feb 13 '20 at 06:52
  • So then why does `python manage.py runserver` still throw the same error despite `python`, `import sqlite3`, `sqlite3.sqlite_version` returning a version compatible with the requirements. – Shmack Feb 25 '21 at 06:59
  • i followed this and killed my VS code and restarted it again, it works. – yts61 May 16 '21 at 17:30
4

In addition to the above mentioned answers, just in case if you experience this behaviour on Travis CI, add dist: xenial directive to fix it.

Artur Barseghyan
  • 12,746
  • 4
  • 52
  • 44
4

I have applied the following fix and it worked for my CentOS 7.x server.

Edit /usr/lib64/python3.6/site-packages/django/db/backends/sqlite3/base.py file as per the below example:

def check_sqlite_version():
# if Database.sqlite_version_info < (3, 8, 3):
# 2018-07-07, edit
if Database.sqlite_version_info < (3, 6, 3):
    raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
Kate Orlova
  • 3,225
  • 5
  • 11
  • 35