Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While installing nltk package getting ModuleNotFoundError: No module named '_sqlite3'

Getting below error while running a code snippet which has nltk dependencies.

Manually installed python 3.6.5 and using it in the virtual enviornment
The OS (Red Hat Linux 7.4-Maipo) has python 2.7.4 installed in it.

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'

Tried below solution but it didn't help (used yum and pip instead) :

solution 1

sudo apt-get install libsqlite3-dev

(Or you can install more packages as suggested on the 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

Now in the downloaded python source rebuild and install python with the following command: ./configure --enable-loadable-sqlite-extensions && make && sudo make install.

My Attempt throwing below error :

Collecting libsqlite3-dev
  Could not find a version that satisfies the requirement libsqlite3-dev (from versions: )
No matching distribution found for libsqlite3-dev
like image 826
Soumyaansh Avatar asked Jun 28 '18 11:06

Soumyaansh


1 Answers

Answering my own question.

Finally fixed the issue by Installing sqlite-devel package :

yum install sqlite-devel

and re-installing the python as follows:

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
like image 146
Soumyaansh Avatar answered Oct 15 '22 10:10

Soumyaansh