Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Using pysqlite3 on macOS#
While trying to use pysqlite3 on macOS I got the following error:
1>>> import pysqlite32Traceback (most recent call last):3 File "<stdin>", line 1, in <module>4 File "/Users/simon/.local/share/virtualenvs/datasette-AWNrQs95/lib/python3.8/site-packages/pysqlite3/__init__.py", line 23, in <module>5 from pysqlite3.dbapi2 import *6 File "/Users/simon/.local/share/virtualenvs/datasette-AWNrQs95/lib/python3.8/site-packages/pysqlite3/dbapi2.py", line 28, in <module>7 from pysqlite3._sqlite3 import *8ImportError: dlopen(/Users/simon/.local/share/virtualenvs/datasette-AWNrQs95/lib/python3.8/site-packages/pysqlite3/_sqlite3.cpython-38-darwin.so, 2): Symbol not found: _sqlite3_enable_load_extension9 Referenced from: /Users/simon/.local/share/virtualenvs/datasette-AWNrQs95/lib/python3.8/site-packages/pysqlite3/_sqlite3.cpython-38-darwin.so10 Expected in: flat namespace11 in /Users/simon/.local/share/virtualenvs/datasette-AWNrQs95/lib/python3.8/site-packages/pysqlite3/_sqlite3.cpython-38-darwin.soThanks to this tip on Stack Overflow I found that installing a fresh SQLite with brew install sqlite3 and then running the following first fixed the error:
1export DYLD_LIBRARY_PATH=/usr/local/opt/sqlite/lib:/usr/libThen:
1>>> import pysqlite32>>> pysqlite3.connect(":memory:").execute("select sqlite_version()").fetchall()3[('3.36.0',)]This is because the Homebrew SQLite is “keg-only”, which means that it does not become the default on the system to avoid intefering with the existing SQLite that ships with macOS.
As illustrated by the following:
1% which sqlite32/usr/bin/sqlite33% echo "select sqlite_version()" | /usr/bin/sqlite343.28.05% echo "select sqlite_version()" | /usr/local/opt/sqlite3/bin/sqlite363.36.0Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.