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??
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With