在运行具有nltk依赖性的代码段时遇到错误。
手动安装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):
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
答案 0 :(得分:5)
回答我自己的问题。
最后通过安装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