Python3安装sqlite3

在运行scrapy脚本时,遇到了一下问题:

raceback (most recent call last):
  File "/usr/local/python3/lib/python3.6/site-packages/Twisted-17.1.0-py3.6-linux-x86_64.egg/twisted/internet/defer.py", line 1301,
 in _inlineCallbacks
    result = g.send(result)
  File "/usr/local/python3/lib/python3.6/site-packages/scrapy/crawler.py", line 82, in crawl
    yield self.engine.open_spider(self.spider, start_requests)
ModuleNotFoundError: No module named '_sqlite3'

上面的错误,原因是因为安装python的时候没有找到sqlite3.so的库。

简单方式

yum install sqlite*

然后重新编译、安装Python3(CentOS安装python3及scrapy

下载安装

如果上面的方式不可以的话,则使用下载安装的方式。

wget https://www.sqlite.org/2017/sqlite-autoconf-3170000.tar.gz --no-check-certificate
tar zxvf sqlite-autoconf-3170000.tar.gz
cd sqlite-autoconf-3170000
./configure --prefix=/usr/local/sqlite3 --disable-static --enable-fts5 --enable-json1 CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1"

# 重新编译安装
cd Python-3.6.0
LD_RUN_PATH=/usr/local/sqlite3/lib ./configure LDFLAGS="-L/usr/local/sqlite3/lib" CPPFLAGS="-I /usr/local/sqlite3/include"
LD_RUN_PATH=/usr/local/sqlite3/lib make
LD_RUN_PATH=/usr/local/sqlite3/lib sudo make install