'Using brew installed sqlite3

I want to use sqlite with the json extension so I've installed it with homebrew. When I run which sqlite though, the one that is being used is the anaconda install. If I try and use pythons sqlite library I have the same issue. It's linked to the Anaconda version and the JSON functions aren't available. How do I replace this with the brew version? Brew provided some values when I installed sqlite but I don't know if I need them or how they are used.

LDFLAGS: -L/usr/local/opt/sqlite/lib CPPFLAGS: -I/usr/local/opt/sqlite/include PKG_CONFIG_PATH: /usr/local/opt/sqlite/lib/pkgconfig



Solution 1:[1]

Sqlite installed by Homebrew is keg-only, which is not linked to /usr/local/... .
This is because system already have older version of sqlite3.

If you really want to invoke Homebrew's sqlite binary, specify full path as below.

$ /usr/local/opt/sqlite/bin/sqlite3

(All Homebrew package is symlinked under /usr/local/opt)

I'm not so familiar with python, but AFAIK sqlite is statically linked to python executable.
In other words, maybe you have to build python from source to use with Homebrew's sqlite.

Solution 2:[2]

The answer by equal-l2 is correct. Also, the comment under it by Keith John Hutchison.

But, since they are from quite a few years ago and there is not an officially accepted answer still, here you go as this still catches you off-guard in 2022.

To fix, add this to your ~/.zshrc file and you should be good:

export PATH=/usr/local/opt/sqlite/bin:$PATH

Remember to have $PATH at the end like the above and not at the beginning like so:

export PATH=$PATH:/usr/local/opt/sqlite/bin

as the shell traverses your $PATH for command completion left to right and stops at the first instance found and obviously you want your desired path to be considered first.

Also, you might need to run source ~/.zshrc and rehash if you want it to just start working in the same terminal session.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2