15
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'
For me the new version of sqlite3 is in /usr/local/bin so 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
66
I got the same error in CentOS 7.6 and Python 3.7.3 versions. I think you are using Django 2.2.* some version. In latest of Django 2.2, they changed the SQLIte version, that cause of your problem.
This is the release notes of Django 2.2 about SQLite.
The minimum supported version of SQLite is increased from 3.7.15 to 3.8.3.
So I found 3 steps to solve this problem,
- Downgrade Django Version
So you can install latest version of Django 2.1 by using this command, which mean youโre going to downgrade your Django
version.
pip install Django==2.1.*
or you can followup below steps as well to keep the latest version Django
. I directly get the steps from Upgrading SQLite on CentOS to 3.8.3 or Later article.
You can download the latest sqlite
version from here.
wget https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
tar zxvf sqlite-autoconf-3280000.tar.gz
./configure
make
sudo make install
Weโve installed to the latest version, but the problem is same. Here,
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'
In the article, theyโve mentioned about LD_RUN_PATH
and LD_LIBRARY_PATH
paths.
Then make sure to compile python again using the
LD_RUN_PATH
environment variable.
It is better to use this variable overLD_LIBRARY_PATH
.
UsingLD_LIBRARY_PATH
โ whenever python is run it will look for linked libraries with that path.
What we want is for the libraries to be cooked into python at link time โ compile time.
So based on the article, we can do the similar thing,
cd /opt/Python-x.y.z
LD_RUN_PATH=/usr/local/lib ./configure
LD_RUN_PATH=/usr/local/lib make
LD_RUN_PATH=/usr/local/lib make altinstall
Then try again,
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.31.1'
Here we go, one thing theyโve mentioned,
If you do not use LD_RUN_PATH, then you have to make sure that the LD_RUN_PATH environment variable is set to /usr/local/lib for every user that is going to run python โ which can be really annoying to do.
This is same as the previous one and based on LD_LIBRARY_PATH
approach. Here is the steps from the article,
$ wget https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
$ tar zxvf sqlite-autoconf-3240000.tar.gz
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$
$ python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.7.17
$
$ export LD_LIBRARY_PATH=/usr/local/lib
$ python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.24.0
If the last two steps didnโt work, please comment below with the error you got and Iโll find another solution for you.
- [Django]-Redirect to same page after POST method using class based views
- [Django]-How to access data when form.is_valid() is false
- [Django]-Django QuerySet order
34
I solved a similar situation with the following patches of code. Follow these steps that I used on my own centos7 & everything should be alright.
Just remember to let your centos7 know that you are calling python3
not just python
otherwise it will call the default python2 followed by a series of errors in your virtualenv
.
Installing python3 (from source):
cd ~
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
tar xJf Python-3.7.3.tar.xz
cd Python-3.7.3
./configure
make && make install
export PATH=$HOME/opt/python-3.7.3/bin:$PATH
Then run: source .bash_profile
Confirming by
python3 --version
Python 3.7.3
Installing your sqlite3 (from source):
$ cd ~
$ wget https://www.sqlite.org/2019/sqlite-autoconf-3290000.tar.gz
$ tar zxvf sqlite-autoconf-3290000.tar.gz
cd sqlite-autoconf-3290000
$./configure --prefix=$HOME/opt/sqlite
$ make && make install
Now this is what you should also remember to do for centos7 know where to look for your python3 and not defaulting to python2. On your .bash_profile
copy & past this piece of code or edit the paths accordingly:
export PATH=$HOME/opt/sqlite/bin:$PATH
export LD_LIBRARY_PATH=$HOME/opt/sqlite/lib
export LD_RUN_PATH=$HOME/opt/sqlite/lib
Make it permanent by running: source .bash_profile
and you are done with sqlite3 version >= 3.8
. Confirm it by:
sqlite3 --version
3.29.0 2019-07-10 17:32:03
And then you can continue to use python3 to install python3 modules like django-2.2.
python3.7 -m pip3 install virtualenv
(myvenv37)[me@test my_project]$ python3.7 -m pip3 install django
Successfully installed django-2.2.3 pytz-2019.1 sqlparse-0.3.0
Remember, it is
PYTHON3.7 -m pip3 install MODULE
(myvenv37)[me@test my_project]$ python3.7 manage.py runserver
and the server should be running.
So, to conclude, in the case above it was migrate
, & should look like this:
(venv)[me@test my_project]$ python3.7 manage.py migrate
- [Django]-Reducing Django Memory Usage. Low hanging fruit?
- [Django]-How to use Python type hints with Django QuerySet?
- [Django]-Deploying Django with gunicorn and nginx
22
As this was about Centos7, you can use the Fedora package to upgrade the Centos sqlite package:
wget https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-3.8.11-1.fc21.x86_64.rpm
sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm
This seems to work, although Iโm never sure if doing this is really an ideal solution to a problem or not. I guess if youโre not actually using SQLite, then this at least passes the version check and so gets you working.
- [Django]-Allow only positive decimal numbers
- [Django]-Django's ManyToMany Relationship with Additional Fields
- [Django]-Django Server Error: port is already in use
16
django 2.2 need sqlite version >= 3.8.3
so the solution is update your sqlite:
- download from sqlite3, select source_code version
- tar -zxvf sqlite-xxx.tar.gz && cd xx
- ./configure && make && make install
- mv /usr/bin/sqlite3 /usr/bin/sqlite3.bak
- mv xxx/sqlite3 /usr/bin/sqlite3
export LD_LIBRARY_PATH="/usr/local/lib"
and write it into ~/.bashrc
test1 :
sqlite3 --version
should be your version
test2:
$python
>>> import sqlite3
>>> sqlite3.sqlite_version
should be your version
- [Django]-Separating form input and model validation in Django?
- [Django]-Django: Switching to Jinja2?
- [Django]-How to have a Python script for a Django app that accesses models without using the manage.py shell?
8
I had the same issue and I struggled with it for a while. For me the best solution was to comment out DATABASES section in settings.py file.
As I donโt want to use SQLite database then issue does not exist anymore. Later on you can update DATABASE information with the db that is valid for you.
- [Django]-Django+Postgres: "current transaction is aborted, commands ignored until end of transaction block"
- [Django]-Catching DoesNotExist exception in a custom manager in Django
- [Django]-Optimal architecture for multitenant application on django
8
You will only get make it worse with errors like multilib and other incompatibilities if keeps forcing the installation of sqlite 3.8.3 or higher. Just as @Theo also commented, the best approach is to comment the line #66 on the sqlite3/base.py (file within django) that triggers the method named check_sqlite_version().
This should just be warning that you are using a minor patch instead of raise an Exception (ImproperlyConfigured). You may also replace the raise with a print.
PD: Just make sure to document it!
- [Django]-Suppress "?next=blah" behavior in django's login_required decorator
- [Django]-Negating a boolean in Django template
- [Django]-Why does django run everything twice?
7
I was having trouble with the above solutions on an Amazon Linux 2 instance and found that what was installed from my various attempts to update were causing version conflicts.
Initially I had this:
$ python3 --version
Python 3.7.9
$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'
>>> exit()
And sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm
failed to install with this message:
I resolved it by the following steps:
sudo yum list | grep sqlite
These two packages were preventing updates due to conflict.
sudo yum autoremove sqlite-devel
To uninstall the extraneous package.
sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm
To update the version.
sudo yum list | grep sqlite
New list of updated sqlite packages:
$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.8.11'
>>> exit()
- [Django]-ImportError: Couldn't import Django
- [Django]-How do I get all the variables defined in a Django template?
- [Django]-Get model's fields in Django
5
After few hours of searching I solved it using one command inside my virtual environment:
pip install pysqlite3-binary
You can check github here and article(a bit outdated) here.
I also found here that you should then place the following lines of code in your settings.py:
__import__('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
but for me it worked without it.
- [Django]-How to escape {{ or }} in django template?
- [Django]-How can I filter a Django query with a list of values?
- [Django]-How can I avoid "Using selector: EpollSelector" log message in Django?
0
another option is to use atomic repo
wget -O - http://updates.atomicorp.com/installers/atomic |sh
yum install atomic-sqlite
LD_LIBRARY_PATH='/opt/atomicorp/atomic/root/usr/lib64/' python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.8.5'
- [Django]-Django logging of custom management commands
- [Django]-The QuerySet value for an exact lookup must be limited to one result using slicing. Filter error
- [Django]-You are trying to add a non-nullable field 'new_field' to userprofile without a default
0
I answered this question here: ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
I solved this issue by upgrading my version of sqlite3 using this command:
cd ~ && wget https://www.sqlite.org/2020/sqlite-autoconf-3320100.tar.gz && tar xvfz sqlite-autoconf-3320100.tar.gz && cd sqlite-autoconf-3320100 && ./configure && make && make install
I am using ElasticBeanstalk for my setup, so I added a .config file to the .ebextensions folder and put this in it:
option_settings:
aws:elasticbeanstalk:application:environment:
LD_LIBRARY_PATH: "/usr/local/lib"
commands:
01_upgrade_sqlite:
command: "cd ~ && wget https://www.sqlite.org/2020/sqlite-autoconf-3320100.tar.gz && tar xvfz sqlite-autoconf-3320100.tar.gz && cd sqlite-autoconf-3320100 && ./configure && make && make install"
Many thanks to Bejรผr for adding the LD_LIBRARY_PATH environment variable here in order to get it to work.
- [Django]-Accepting email address as username in Django
- [Django]-Django filter on the basis of text length
- [Django]-How to view database and schema of django sqlite3 db
- [Django]-Get last record in a queryset
- [Django]-Getting a count of objects in a queryset in Django
- [Django]-Difference between different ways to create celery task
0
Another hacky way to solve it: build from source and replace lib files.
FROM public.ecr.aws/lambda/python:3.9
RUN cd /tmp && \
curl -L -O https://www.sqlite.org/2023/sqlite-autoconf-3410200.tar.gz && \
tar -xzf sqlite-autoconf-3410200.tar.gz && \
cd sqlite-autoconf-3410200 && \
./configure && \
make -j$(nproc) && \
make install && \
cp /usr/local/lib/libsqlite3.so /var/lang/lib/libsqlite3.so && \
cp /usr/local/lib/libsqlite3.so.0 /var/lang/lib/libsqlite3.so.0 && \
cp /usr/local/lib/libsqlite3.so.0.8.6 /var/lang/lib/libsqlite3.so.0.8.6 && \
cp /usr/local/lib/libsqlite3.so.0 /usr/lib64/libsqlite3.so.0 && \
cp /usr/local/lib/libsqlite3.so.0.8.6 /usr/lib64/libsqlite3.so.0.8.6
- [Django]-How do I display the Django '__all__' form errors in the template?
- [Django]-Django: For Loop to Iterate Form Fields
- [Django]-Alternate Row Coloring in Django Template with More Than One Set of Rows
-2
i had recently same problem
My solution was to change source code site-packages\django\db\backends\sqlite3\base.py line around 68 So far no side effects.
def check_sqlite_version():
if Database.sqlite_version_info < (3, 7, 3):
raise ImproperlyConfigured(โSQLite 3.8.3 or later is required (found %s).โ % Database.sqlite_version)
- [Django]-Foreign Key Django Model
- [Django]-Auto-reloading of code changes with Django development in Docker with Gunicorn
- [Django]-Django+Postgres: "current transaction is aborted, commands ignored until end of transaction block"