Symbol not found: _sqlite3_enable_load_extension - sqlite installed via homebrew
Asked Answered
E

4

14

Symptom: In my Django app, when I call from pysqlite2._sqlite import * I get the traceback Symbol not found: _sqlite3_enable_load_extension when

Background:

  • I've installed python using homebrew (python 2.7.13), which auto installed sqlite
  • I am running macOS 10.12.3 with Command Line Tools macOS 10.12, Xcode 8.2.1
  • I've installed pysqlite using pip (pysqlite 2.8.3)

I have tried

  • brew uninstall sqlite and brew uninstall python and reinstalling
  • Adding these to my .bash_profile

    export PATH="$(brew --prefix sqlite)/bin:$PATH"
    LDFLAGS="-L/usr/local/opt/sqlite/lib"
    CPPFLAGS="-I/usr/local/opt/sqlite/include"
    export PKG_CONFIG_PATH=“/usr/local/opt/sqlite/lib/pkgconfig”
    
  • python -c "import sqlite3" doesn't return any errors

Gist of traceback: https://gist.github.com/xwchen/e9704fa34f0463d2117fe9fbb37922a1

Eades answered 2/2, 2017 at 4:56 Comment(1)
I have now the same Symbol not found: _sqlite3_enable_load_extension error. I reinstalled python2, python3 and sqlite without any success and I cant find a google page anymore which helps me. I also added several environment variables. Like LDFLAGS, CPPFLAGS, PKG_CONFIG_PATH, DYLD_LIBRARY_PATH I am using python 2.7 in <- virtual environment with Mac OS 10.15.6 please help.Copperplate
U
14

Copied answer from here (https://github.com/Homebrew/homebrew-core/pull/3134). If you're like me, you probably installed sqlite after you install python3. Anyway, if anyone stumbles upon this question and needs an answer...

First remove SQLite, python and python3 if installed via homebrew

brew uninstall --force python
brew uninstall --force python3
brew uninstall --force sqlite

This removes all copies.

Then make sure Xcode 8 or later is installed

Important

Re-install command line tools via

xcode-select --install
sudo xcode-select --reset

and finally install command line tools via pkg file found here.

Look for command line tools in search. (I've downloaded "Command Line Tools (macOS 10.12) for Xcode 8.dmg") Then open DMG and install the pkg found there.

Now install SQLite and then python and python 3 if needed:

brew install sqlite
brew install python
brew install python3

Run brew install python --verbose and make sure there are no warnings, if none then issues should be resolved.

Don't forget to do

pip install setuptools --upgrade && pip3 install setuptools --upgrade
Understanding answered 16/10, 2017 at 5:45 Comment(2)
This didn't worked for me. I am trying since months to get up an oder project running with python 2.7 on virtual environment. but I keep getting the error message Symbol not found: _sqlite3_enable_load_extension. Can some one help me?Copperplate
You should avoid using system python and any homebrew versions of python for development. Use pyenv instead. Run brew install pyenv. pyenv install 2.7.18 and you can set the local python in your shell env as pyenv shell 2.7.18Understanding
E
9

It may happen because it's not able to locate the .so library. As explained here:

On OS X, homebrew installs sqlite3 as “keg-only” because otherwise it interferes with the system sqlite3. This means that libsqlite3.dylib ends up in /usr/local/opt/sqlite/lib, not in /usr/local/lib

So you can simply do this:

export DYLD_LIBRARY_PATH=/usr/local/opt/sqlite/lib:/usr/lib

Then you should be able to import sqlite3.

Estaminet answered 3/2, 2020 at 20:46 Comment(4)
+1 I was having this issue with [email protected]. Solved it without reinstalling, just: export DYLD_LIBRARY_PATH="/opt/homebrew/Cellar/sqlite/3.35.5/lib:/usr/local/lib:/usr/local/include:/usr/lib:/usr/include"Haitian
none of these worked for me on M1 with [email protected].Pragmaticism
I was getting Symbol not found: _sqlite3_aggregate_context error. Without much understanding, I tried this method, and it just worked and now I can launch Jupyter.Ruff
Using the same conda environment, I can run Jupyter by jupyer notebook but I still cannot use Jupyter on VScode and am still having the same error Symbol not found: _sqlite3_aggregate_contextRuff
C
5

In my conda environment simply running conda install sqlite fixed it.

Cageling answered 3/1, 2023 at 19:39 Comment(0)
A
1

On my Linux, it was because of a libsqlite3.so.0 located in /usr/local/lib folder. In this case, it was from Filezilla nightly builds using another sqlite3 version.

To find the links of the share object, use ldd

$ ldd /usr/lib/python3.12/lib-dynload/_sqlite3.cpython-312-x86_64-linux-gnu.so
linux-vdso.so.1 (0x00007ffc92b56000)
libsqlite3.so.0 => /usr/local/lib/libsqlite3.so.0 (0x00007bc7625fb000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007bc762200000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007bc7625dc000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007bc7624f1000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007bc7624ec000)
/lib64/ld-linux-x86-64.so.2 (0x00007bc762771000)

And the problematic file was libsqlite3.so.0 => /usr/local/lib/libsqlite3.so.0 so I just removed it

Note that /usr/local/lib/ often takes over the system libs from /usr/lib/, that's why it used the wrong libsqlite3.so shared object

Albuquerque answered 15/3 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.