5

I'm running a Django project using sqlite as one of the databases. I would like to run the most recent SQLite version when running the project. By that I mean the most recent sqlite binary, not the sqlite python library.

I have a local sqlite3 binary that is not the system default and I can't change the default sqlite3 version.

I'm not using Django's ORM but have replaced it with a standalone SQLAlchemy version.

I've found one related link but that had to do with running the most recent python sqlite library version.

How to upgrade sqlite3 in python 2.7.3 inside a virtualenv?

Community
  • 1
  • 1
danihodovic
  • 972
  • 3
  • 12
  • 25
  • What do you mean by the binary though? As you seem to know, Python doesn't use the binary, it uses its own compiled library. So the binary is not connected with Python in any way, and I don't see what the question has to do with Python or sqlalchemy. – Daniel Roseman Mar 26 '15 at 15:28
  • So how do I update/replace the python compiled binary in a virtualenv? I mentioned SQLAlchemy, Python and Django as I'm not sure where the problem is exactly. – danihodovic Mar 26 '15 at 15:31
  • 1
    Virtualenvs are for Python code. Python does not use the binary. If you want to replace the version of the sqlite library that Python uses to run code, that linked question provides the exact answer. – Daniel Roseman Mar 26 '15 at 15:33

2 Answers2

1

Python can't use the sqlite3 binary directly. It always uses a module which is linked against the sqlite3 shared library. That means you have to follow the instructions in "How to upgrade sqlite3 in python 2.7.3 inside a virtualenv?" to create a version of the pysqlite module in your virtualenv.

You can then use this import

from pysqlite2 import dbapi2 as sqlite

to shadow the system's default sqlite module with the new one.

Another option would be to get Python's source code, compile everything and copy the file sqlite.so into your virtualenv. The drawback of this approach is that it's brittle and hard to repeat by other people.

Community
  • 1
  • 1
Aaron Digulla
  • 310,263
  • 103
  • 579
  • 794
  • 1
    Probably an impossible question for you to answer, but how would this work when using SQLAlchemy which builds on top of pysqlite? – danihodovic Mar 29 '15 at 21:16
  • 1
    Please ask a new question for that and show us the code which you use to set up SQLAlchemy (i.e. how do you create a DB connection). – Aaron Digulla Mar 30 '15 at 10:51
  • For those of you who are getting a `undefined symbol: PyOS_mystrnicmp` error when doing this import, see this (currently unanswered) question: http://stackoverflow.com/questions/39975712/undefined-symbol-pyos-mystrnicmp – Pieter Oct 11 '16 at 13:31
0

Try this easy route first if you're on windows: grab the dll from the sqlite download page (it will be under the "Precompiled Binaries for Windows" heading) and add it to Anaconda's dll path (like C:\Users\YourUserName\Anaconda3\DLLs). The new versions there come with goodies like FTS5 already enabled.

If you're on Linux, then refer to Install Python and Sqlite from Source and Compiling SQLite for use with Python Applications

zelusp
  • 3,145
  • 3
  • 29
  • 61