使用pyenv安装的python导入'_sqlite3'模块时找不到

时间:2018-11-03 03:21:09

标签: python macos sqlite pip homebrew

pyenv在macOS上安装了python 3.7.0。

sqlite3已安装:

which sqlite3
/usr/bin/sqlite3

还尝试通过pip安装pysqlite3

pip install pysqlite3

但是在导入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'

是否需要通过brew在macOS上为sqlite3安装开发库?

1 个答案:

答案 0 :(得分:13)

这种方式有效:

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

参考:

  

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