nz_21
nz_21

Reputation: 7343

Python3.7 Nltk ModuleNotFoundError: No module named '_sqlite3

I'm using pipenv to manage my dependencies - here's my pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
elasticsearch-dsl = "*"
spacy = "*"

nltk = "*"
"pysqlite3" = "*"

[dev-packages]

[requires]
python_version = "3.7"

When trying to run an app that uses NLTK, I get the following error:

  File "/home/dell/swipe_xkcd/cron/populate_db.py", line 7, in <module>
    from scraper import xkcd_scraper
  File "/home/dell/swipe_xkcd/scraper/xkcd_scraper.py", line 13, in <module>
    from nltk.corpus import stopwords
  File "/home/dell/swipe_xkcd/venv/lib/python3.7/site-packages/nltk/__init__.py", line 150, in <module>
    from nltk.translate import *
  File "/home/dell/swipe_xkcd/venv/lib/python3.7/site-packages/nltk/translate/__init__.py", line 23, in <module>
    from nltk.translate.meteor_score import meteor_score as meteor
  File "/home/dell/swipe_xkcd/venv/lib/python3.7/site-packages/nltk/translate/meteor_score.py", line 10, in <module>
    from nltk.stem.porter import PorterStemmer
  File "/home/dell/swipe_xkcd/venv/lib/python3.7/site-packages/nltk/stem/__init__.py", line 29, in <module>
    from nltk.stem.snowball import SnowballStemmer
  File "/home/dell/swipe_xkcd/venv/lib/python3.7/site-packages/nltk/stem/snowball.py", line 32, in <module>
    from nltk.corpus import stopwords
  File "/home/dell/swipe_xkcd/venv/lib/python3.7/site-packages/nltk/corpus/__init__.py", line 66, in <module>
    from nltk.corpus.reader import *
  File "/home/dell/swipe_xkcd/venv/lib/python3.7/site-packages/nltk/corpus/reader/__init__.py", line 105, in <module>
    from nltk.corpus.reader.panlex_lite import *
  File "/home/dell/swipe_xkcd/venv/lib/python3.7/site-packages/nltk/corpus/reader/panlex_lite.py", line 15, in <module>
    import sqlite3
  File "/home/dell/.pyenv/versions/3.7.3/lib/python3.7/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/home/dell/.pyenv/versions/3.7.3/lib/python3.7/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

How do I fix this?

I have tried sudo apt install libsqlite3-dev but that didn't work - the same error persisted.

I've also tried installing pysqlite but to no avail.

Upvotes: 0

Views: 1627

Answers (1)

nz_21
nz_21

Reputation: 7343

Solved

I installed my python with pyenv a while back. It didn't pick up libsqlite3-dev as I didn't have it at the time, so the solution was to reinstall python like so:

pyenv install 3.7.1

Upvotes: 1

Related Questions