0

I'm using buildroot to add python nltk package. When I try to import nltk, it gives the error as follows,

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'

in the core python3 modules, I select sqlite module, and in database, I select sqlite, but it doesn't work.

Here are some cmd I tried

# 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 is extracted and installed from pypi

Can I get some help, pls?

kinder chen
  • 1,371
  • 5
  • 15
  • 25
  • Weird. Python version? How did you install nltk? – PChemGuy Oct 26 '22 at 04:39
  • python version is 3.10.5, I downloaded and installed nltk from https://pypi.org/project/nltk/, and then `pip install` – kinder chen Oct 26 '22 at 05:18
  • Can you import sqlite3 in Python console? – PChemGuy Oct 26 '22 at 06:23
  • Does this answer your question? [ModuleNotFoundError: No module named '\_sqlite3'](https://stackoverflow.com/questions/43993890/modulenotfounderror-no-module-named-sqlite3) or this https://stackoverflow.com/questions/55170966/importerror-no-module-named-sqlite3 – PChemGuy Oct 26 '22 at 06:28
  • no, when I try `import sqlite3`, it gives `ModuleNotFoundError: No module named 'sqlite3'`, the answers from the link does not work for my question. – kinder chen Oct 26 '22 at 08:49
  • Well, since you cannot import it, sqlite3 module is not properly installed. Did you compile Python yourself? Either way, this question may need to be migrated to *superuser* and it has nothing to do with sqlite. – PChemGuy Oct 26 '22 at 09:06
  • Did you do a full clean build after selecting `sqlite module` in the python3 options? If not, you need to do `make python3-reconfigure world` to explicitly rebuild python3 with the changed option. – Arnout Oct 26 '22 at 09:20
  • @Arnout thanks, shall I `make python3-rebuild` ? does `make brt` work? – kinder chen Oct 26 '22 at 10:19
  • @PChemGuy thanks, I compiled Python from source code – kinder chen Oct 26 '22 at 10:20
  • @kinderchen It has to be `make python3-reconfigure` to take into account the new configuration. I put `world` behind it to make sure the final rootfs is rebuilt as well - by default, `make python3-reconfigure` will *only* reconfigure and rebuild the python3 package, but not re-create the rootfs archive. I don't know what you mean with `make brt`, there is no "brt" package in Buildroot. – Arnout Oct 27 '22 at 07:09
  • thanks, `reconfigure` works, when shall I use `rebuild` and when `reconfigure`? when I need to use `world` ? BTW, do you mind helping check this [question](https://stackoverflow.com/questions/74223700/numpy-distutils-system-info-notfounderror-no-blas-lapack-libraries-found), I appreciate your help – kinder chen Oct 27 '22 at 14:30

1 Answers1

0

My suspicion is that you did a build with BR2_PACKAGE_PYTHON3 enabled and BR2_PACKAGE_PYTHON3_SQLITE disabled. Then you realized that the Sqlite support in Python was missing, so you went on and enabled BR2_PACKAGE_PYTHON3_SQLITE, and you simply ran make. Due to how Buildroot works, this did not cause the python3 package to be rebuilt, so you still have a python3 without Sqlite support.

Two options:

  1. Rebuild just python3 by doing make python3-dirclean all
  2. Rebuild the whole system by doing make clean all
Thomas Petazzoni
  • 5,636
  • 17
  • 25