Python3.7 Nltk ModuleNotFoundError:没有名为'_sqlite3的模块

时间:2019-08-06 18:12:54

标签: python-3.x sqlite nltk pipenv

我正在使用pipenv来管理我的依赖项-这是我的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"

当尝试运行使用NLTK的应用程序时,出现以下错误:

  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'

该如何解决?

我尝试了sudo apt install libsqlite3-dev,但没有成功-仍然存在相同的错误。

我也尝试安装pysqlite,但无济于事。

1 个答案:

答案 0 :(得分:1)

已解决

我前一阵子用pyenv安装了python。由于当时我没有libsqlite3-dev,所以它没有启动,所以解决方案是像这样重新安装python:

pyenv install 3.7.1