You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Buildroot环境导入nltk报错:No module named 'sqlite3'求助

问题:Buildroot环境下Python导入nltk时提示缺少sqlite3模块

执行import nltk时出现如下错误:

import nltk
  File "/usr/lib/python3.10/site-packages/nltk/__init__.py", line 152, in <module>
    from nltk.translate import *
  File "/usr/lib/python3.10/site-packages/nltk/translate/__init__.py", line 24, in <module>
    from nltk.translate.meteor_score import meteor_score as meteor
  File "/usr/lib/python3.10/site-packages/nltk/translate/meteor_score.py", line 13, in <module>
    from nltk.corpus import WordNetCorpusReader, wordnet
  File "/usr/lib/python3.10/site-packages/nltk/corpus/__init__.py", line 64, in <module>
    from nltk.corpus.reader import *
  File "/usr/lib/python3.10/site-packages/nltk/corpus/reader/__init__.py", line 106, in <module>
    from nltk.corpus.reader.panlex_lite import *
  File "/usr/lib/python3.10/site-packages/nltk/corpus/reader/panlex_lite.py", line 15, in <module>
    import sqlite3
ModuleNotFoundError: No module named 'sqlite3'

已在Buildroot的core python3 modules中勾选sqlite module,database中选择sqlite,但问题未解决。当前环境信息:

# python --version
Python 3.10.5

# python3 --version
Python 3.10.5

# find / -name sqlite*
/usr/bin/sqlite3

# pip list
Package       Version
------------- ---------
click         8.1.3
colorama      0.4.4
joblib        1.2.0
nltk          3.7
numpy         1.23.3
pip           21.2.4
regex         2022.9.13
SciPy         1.8.0
setuptools    63.2.0
threadpoolctl 3.1.0
tqdm          4.40.1

nltk-3.7通过pip安装。


解决步骤
  • 重新确认Buildroot配置细节

    1. 执行make menuconfig进入配置界面
    2. 进入Target packages -> Interpreter languages and scripting -> Python -> python3 -> Core python3 modules,确保sqlite3 module被勾选,同时检查下方依赖项是否都被自动选中
    3. 进入Target packages -> Libraries -> Database,确认sqlite已勾选,默认编译配置即可
  • 清理缓存并重新编译
    旧编译缓存可能导致模块未正确生成,执行以下命令重新编译:

    make clean
    make
    
  • 验证sqlite3模块文件是否存在
    编译完成后,检查目标系统中Python动态库路径是否存在_sqlite3.so:

    ls /usr/lib/python3.10/lib-dynload/_sqlite3.so
    

    如果该文件不存在,说明模块编译失败,需重新检查Buildroot配置,排查编译日志中的错误信息。

  • 确保nltk安装到正确Python环境
    用系统Python的pip重新安装nltk,避免环境混淆:

    python3 -m pip install nltk
    

内容的提问来源于stack exchange,提问作者kinder chen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 12:05:34