5

Using Django and SQLite I want to run most recent SQLite version; most recent SQLite binary, not the SQLite Python library. I have an SQLite binary that is not the system default and can't change the default version.

I'm not using Django's ORM but replaced it with a standalone SQLAlchemy version. Related (but has to do with running the most recent Python SQLite library).

3
  • 1
    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. Commented Mar 26, 2015 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. Commented Mar 26, 2015 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. Commented Mar 26, 2015 at 15:33

3 Answers 3

3

The simplest option if you just need a recent version of SQLite from python is now to install the pysqlite3 package (LINUX ONLY at the time of writing, per the project's README file):

pip install pysqlite3-binary

This comes with a recent version of SQLite statically-linked. You can use it in a venv without affecting any other package.

You can use it like this:

from pysqlite3 import dbapi2 as sqlite3
print(sqlite3.sqlite_version)

If you happen to be using peewee, it will pick it up automatically.

If you need a specific version of SQLite, you can build this package, as suggested in Aaron Digulla's answer.

Sign up to request clarification or add additional context in comments.

2 Comments

This is not working at all on linux.
Just tried it and it still works for me. Perhaps you can ask a separate question with the details on what isn't working.
1

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

Comments

0

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.

3 Comments

Probably an impossible question for you to answer, but how would this work when using SQLAlchemy which builds on top of pysqlite?
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).
For those of you who are getting a undefined symbol: PyOS_mystrnicmp error when doing this import, see this (currently unanswered) question: stackoverflow.com/questions/39975712/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.