安装 nltk 包时出现 ModuleNotFoundError: No module named '_sqlite3'
Posted
技术标签:
【中文标题】安装 nltk 包时出现 ModuleNotFoundError: No module named \'_sqlite3\'【英文标题】:While installing nltk package getting ModuleNotFoundError: No module named '_sqlite3'安装 nltk 包时出现 ModuleNotFoundError: No module named '_sqlite3' 【发布时间】:2018-12-07 11:36:17 【问题描述】:运行具有 nltk 依赖项的代码 sn-p 时出现以下错误。
手动安装python 3.6.5
并在虚拟环境中使用
操作系统(Red Hat Linux 7.4-Maipo
)安装了python 2.7.4
。
Traceback (most recent call last):
File "FLASK_RECOMMENDER_VER_1_1.py", line 15, in <module>
import nltk
File "/home/ec2-user/RecommenderEngine/re_env/lib/python3.6/site-packages/nltk/__init__.py", line 137, in <module>
from nltk.stem import *
File "/home/ec2-user/RecommenderEngine/re_env/lib/python3.6/site-packages/nltk/stem/__init__.py", line 29, in <module>
from nltk.stem.snowball import SnowballStemmer
File "/home/ec2-user/RecommenderEngine/re_env/lib/python3.6/site-packages/nltk/stem/snowball.py", line 32, in <module>
from nltk.corpus import stopwords
File "/home/ec2-user/RecommenderEngine/re_env/lib/python3.6/site-packages/nltk/corpus/__init__.py", line 66, in <module>
from nltk.corpus.reader import *
File "/home/ec2-user/RecommenderEngine/re_env/lib/python3.6/site-packages/nltk/corpus/reader/__init__.py", line 105, in <module>
from nltk.corpus.reader.panlex_lite import *
File "/home/ec2-user/RecommenderEngine/re_env/lib/python3.6/site-packages/nltk/corpus/reader/panlex_lite.py", line 15, in <module>
import sqlite3
File "/usr/local/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
尝试了以下解决方案,但没有帮助(改用 yum 和 pip):
solution 1
sudo apt-get install libsqlite3-dev
(或者您可以按照 pyenv wiki 上的建议安装更多软件包:apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev
现在在下载的python源代码中使用以下命令重建并安装python:./configure --enable-loadable-sqlite-extensions && make && sudo make install。
我的尝试抛出错误:
Collecting libsqlite3-dev
Could not find a version that satisfies the requirement libsqlite3-dev (from versions: )
No matching distribution found for libsqlite3-dev
【问题讨论】:
【参考方案1】:回答我自己的问题。
最后通过安装 sqlite-devel 包解决了这个问题:
yum install sqlite-devel
并重新安装python如下:
sudo wget http://python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
tar xf Python-3.6.5.tar.xz
cd Python-3.6.5
sudo ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
sudo ./configure --enable-optimizations
sudo make && sudo make altinstall
【讨论】:
只是想补充一点,这也修复了我的虚拟 python 环境,ty 执行起来花了很多时间,有人遇到过吗? @jht 你的意思是多长时间?我没有启用优化,我的电脑花了几分钟的时间来编译和链接所有内容。我认为这可能是相当合理的,但优化可能会更长一些。以上是关于安装 nltk 包时出现 ModuleNotFoundError: No module named '_sqlite3'的主要内容,如果未能解决你的问题,请参考以下文章