12

Installed python 3.7.0 by pyenv on macOS.

sqlite3 has been installed:

which sqlite3
/usr/bin/sqlite3

Also tried to install pysqlite3 by pip:

pip install pysqlite3

But can't find module when import sqlite3:

In [1]: import sqlite3
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-5239c6be4108> in <module>
----> 1 import sqlite3

~/.pyenv/versions/3.7.0/lib/python3.7/sqlite3/__init__.py in <module>
     21 # 3. This notice may not be removed or altered from any source distribution.
     22
---> 23 from sqlite3.dbapi2 import *

~/.pyenv/versions/3.7.0/lib/python3.7/sqlite3/dbapi2.py in <module>
     25 import collections.abc
     26
---> 27 from _sqlite3 import *
     28
     29 paramstyle = "qmark"

ModuleNotFoundError: No module named '_sqlite3'

Is it necessary to install a develop library for sqlite3 on macOS by brew?

2 Answers 2

34

This way works:

CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.7.0

Ref:

https://github.com/pyenv/pyenv/issues/108#issuecomment-359161050

Sign up to request clarification or add additional context in comments.

2 Comments

what if I'm not on mac and dont have xcrun
github.com/pyenv/pyenv/wiki#suggested-build-environment. ensure sqlite related packages are installed
0

I found a easy way to fix this if you're using pyenv. Run:

sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

Assuming you already have pyenv installed, install a new version of python in pyenv:

pyenv install 3.8.10 

(change the python version to whatever you want).

Your new version of python should have the required dependencies like sqlite3.

1 Comment

OP is on MacOS though, so apt is not available

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.