Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find '_sqlite3' module when import it using python which installed by pyenv

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?

like image 751
Jingqiang Zhang Avatar asked Nov 03 '18 03:11

Jingqiang Zhang


1 Answers

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

like image 102
Jingqiang Zhang Avatar answered Sep 20 '22 18:09

Jingqiang Zhang