0

I've developed a website in Django (3.0.8) using the latest Python version (3.8.3). I'm working on a Unix server with Python 3.6.9 installed, which includes Sqlite version 3.7.17. Django apparently requires Sqlite 3.8 or higher.

So, I compiled a local copy of the latest Python following the guide here: https://www.a2hosting.com/kb/developer-corner/python/using-a-newer-version-of-python

I set up a virtual environment as described above and everything is working smoothly, except that Python is still using the old Sqlite version. After hours of work trying to figure all this out I'm stumped.

I can access Python and Sqlite3 via command line in standard environment:

-bash-4.2$ python --version
Python 3.6.9

-bash-4.2$ python
>>> import sqlite3, inspect
>>> sqlite3.sqlite_version
'3.7.17'

>>> inspect.getfile(sqlite3)
'opt/rh/rh-python36/root/usr/lib64/python3.6/sqlite3/__init__.py'

and in virtual environment:

-bash-4.2$ source bin/venv/bin/activate
(venv) -bash-4.2$ python --version
Python 3.8.3

-bash-4.2$ python
>>> import sqlite3, inspect
>>> sqlite3.sqlite_version
'3.7.17'

>>> inspect.getfile(sqlite3)
'users/.../lib/python3.8/sqlite3/__init__.py

So, despite running Python 3.8.3 and pointing to the correct library (as far as I can tell) in the virtual environment, the sqlite version is still the same as the standard environment. Any suggestions would be greatly appreciated!

Sideek
  • 3
  • 3

2 Answers2

0

SQlite3 is part of a python installation and is not an external library, i.e. you cannot upgrade using a package manager like pip. With each python version you will have a different Sqltie version. However, this is not true if you have replaced the dll files. I have seen some users do this on windows and to me this is rather a risky approach.

If you have replaced the dlls then try reverting that and the output of this should be distinct from python 3.6.9

-bash-4.2$ python
>>> import sqlite3, inspect
>>> sqlite3.sqlite_version
'3.7.17'  # would be different version here

You can also (if you want), download the sqlite3.dll (pre-compiled binary) file from here of a version >=Sqlite 3.8. Then copy over this file in the DLLs folder in the python installation directory. You may want to make a backup of your old sqlite3.dll file just in case you may decide to revert.

AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35
  • Sorry, I forgot to include that I'm working on a Unix server without root access, so no DLLs. I added that to my question. I did install the latest version of Python, which should have included the latest Sqlite3. When I look at the sqlite3 file in my local install, however, it still shows the older version. – Sideek Jul 12 '20 at 16:35
  • Hmm. Can you try doing complete uninstall of all python version and install a new latest one. This should solve the problem. – AzyCrw4282 Jul 12 '20 at 16:42
  • @Sideek can you also try to run `-bash-4.2$ python3` and then try to find the version of `sqlite` and see if there's any difference. Also, you can run the cmd `where python` and `where python3` to find the correct result that should be located within your `venv` – AzyCrw4282 Jul 12 '20 at 17:04
  • When I run -bash-4.2$ python3 and read the sqlite version I get '3.7.17', which is the same that I get when I run python, and also the same as when I do this in my venv (even though the python version is indeed different in the venv) – Sideek Jul 12 '20 at 23:19
  • Hmm. It looks like the only way i can think is to uninstall `Python 3.6.9`. – AzyCrw4282 Jul 12 '20 at 23:21
  • Running whereis python in standard env: python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /opt/rh/rh-python36/root/usr/bin/python /opt/rh/rh-python36/root/usr/bin/python3.6 /opt/rh/rh-python36/root/usr/bin/python3.6m /opt/rh/rh-python36/root/usr/bin/python3.6-config /opt/rh/rh-python36/root/usr/bin/python3.6m-config /opt/rh/rh-python36/root/usr/bin/python3.6m-x86_64-config /usr/share/man/man1/python.1.gz – Sideek Jul 12 '20 at 23:22
  • Unfortunately Python 3.6.9 is what is installed on the server, which is managed by my university. Simply uninstalling and upgrading isn't an option. Installing Python 3.8.3 as a venv was my workaround. – Sideek Jul 12 '20 at 23:26
  • In the venv: (venv) -bash-4.2$ whereis python3 python3: /users/d/e/devphys/bin/venv/bin/python3 /users/d/e/devphys/bin/venv/bin/python3.8 /opt/rh/rh-python36/root/usr/bin/python3 /opt/rh/rh-python36/root/usr/bin/python3.6 /opt/rh/rh-python36/root/usr/bin/python3.6m /opt/rh/rh-python36/root/usr/bin/python3.6-config /opt/rh/rh-python36/root/usr/bin/python3.6m-config /opt/rh/rh-python36/root/usr/bin/python3.6m-x86_64-config – Sideek Jul 12 '20 at 23:27
  • it simply suggests that your `python` and `python3` both resolves to `python3.6.x`. This is ofc exected since the Unix server is with Python 3.6.9 installed. My final hope is the solutions here https://stackoverflow.com/questions/14541869/how-to-upgrade-sqlite3-in-python-2-7-3-inside-a-virtualenv . Other than that i am helpless – AzyCrw4282 Jul 12 '20 at 23:33
0

Okay, the answer provided by Laenka-Oss solved my problem with minor adjustments: django can't find new sqlite version? (SQLite 3.8.3 or later is required (found 3.7.17))

Install Sqlite from source:

cd ~
wget https://www.sqlite.org/2020/sqlite-autoconf-3320300.tar.gz
tar zxvf sqlite-autoconf-3290000.tar.gz
cd sqlite-autoconf-3290000

./configure --prefix=$HOME/opt/sqlite --disable-dynamic-extensions --enable-static --disable-shared
make && make install

Update library paths by adding these lines to your .bash_profile:

export PATH=$HOME/opt/sqlite/bin:$PATH
export LD_LIBRARY_PATH=$HOME/opt/sqlite/lib
export LD_RUN_PATH=$HOME/opt/sqlite/lib

Install Python from source:

cd ~
wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz
tar xJf Python-3.8.3.tar.xz
cd Python-3.8.3
./configure --prefix=$HOME/opt
make && make install

Now update Python path by adding this to the end of your .bash_profile:

export PATH=$HOME/opt/Python-3.8.3/bin:$PATH

Check that everything worked:

source .bash_profile
python3 --version
Python 3.8.3

python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.32.3'

If you encounter a "SqLite header and version mismatch: ..." error, make sure you run source .bash_profile or restart your connection. If that doesn't work, then double check the sqlite install used the commands shown above.

Your .bash_profile should look like:

export PATH=$HOME/opt/sqlite/bin:$PATH
export LD_LIBRARY_PATH=$HOME/opt/sqlite/lib
export LD_RUN_PATH=$HOME/opt/sqlite/lib
export PATH=$HOME/opt/Python-3.8.3/bin:$PATH
Sideek
  • 3
  • 3