9

On python3.7.4 loading sqlite3 modules and requesting to enable_load_extension gives:

import sqlite3
conn=sqlite3.connect("./tests/data/ne_110m_admin_0_countries.sqlite")
conn.enable_load_extension(True)

AttributeError: 'sqlite3.Connection' object has no attribute 'enable_load_extension'

I understand the default Ubuntu sqlite3 package is building with load_extension deactivated. I have followed this guideline: https://charlesleifer.com/blog/compiling-sqlite-for-use-with-python-applications/

Basically, compiled sqlite3 with flag: -DSQLITE_ENABLE_LOAD_EXTENSION, using pyenv and building python 3.7.4 on verbose mode I can see the load extension flag being used, also following hte above tutorial and reinstalling pysqlite3 on pyenv

Running python on verbose mode:

>>> import sqlite3
# /home/jesus/.pyenv/versions/3.7.4/lib/python3.7/sqlite3/__pycache__/__init__.cpython-37.pyc matches /home/jesus/.pyenv/versions/3.7.4/lib/python3.7/sqlite3/__init__.py

The path to the module is correct.

Using the sqlite3 client:

jesus@earth:~/.pyenv/versions/3.7.4/bin$ sqlite3
SQLite version 3.31.0 2019-11-16 12:04:38
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> SELECT sqlite_compileoption_used('ENABLE_LOAD_EXTENSION');
1

I see that sqlite was build with the proper options

Never the the less I continue to have the same error of: AttributeError: 'sqlite3.Connection' object has no attribute 'enable_load_extension'

Update Requesting by SQL, if the library was compiled with load extension loading the reply is positive

cursor=conn.cursor() 
res=cursor.execute("SELECT sqlite_compileoption_used('ENABLE_LOAD_EXTENSION');") 
res.fetchall() [(1,)]

I am lost on what more can I do to debug the problem. This is happening on pyenv build

Any tips??

3
  • Pick one from [python] sqlite3 version Commented Nov 16, 2019 at 15:15
  • 2
    Are you sure that Python and sqlite3 use the same library? Maybe try the "SELECT sqlite_compileoption_used..." from a Python script. Commented Nov 16, 2019 at 15:17
  • ``` cursor=conn.cursor() res=cursor.execute("SELECT sqlite_compileoption_used('ENABLE_LOAD_EXTENSION');") res.fetchall() [(1,)] ``` Commented Nov 16, 2019 at 16:09

2 Answers 2

9

The python has to be installed with augmented system variables for SQLite and python options. This works for me:

# Do the following in your shell
LDFLAGS="-L/usr/local/opt/sqlite/lib -L/usr/local/opt/zlib/lib" CPPFLAGS="-I/usr/local/opt/sqlite/include -I/usr/local/opt/zlib/include" PYTHON_CONFIGURE_OPTS="--enable-loadable-sqlite-extensions" pyenv install 3.7.6
Sign up to request clarification or add additional context in comments.

1 Comment

This worked for me! Just replaced pyenv with asdf python.
0

For someone who uses macOS, brew and pyenv:

brew install sqlite
LDFLAGS="-L$(brew --prefix sqlite)/lib" CPPFLAGS="-I$(brew --prefix sqlite)/include" PYTHON_CONFIGURE_OPTS="--enable-loadable-sqlite-extensions" pyenv install -v 3.11.4

Comments

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.