2019独角兽企业重金招聘Python工程师标准>>>
环境说明
- 系统版本:centos7
- sqlite版本:3.2
- python版本:python3.6
下载安装
下载地址
http://www.sqlite.org/2018/sqlite-autoconf-3230100.tar.gz
解压安装
tar xvf sqlite-autoconf-3230100
cd sqlite-autoconf-3230100
./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"
make
make install
为方便操作创建软件接
cd /usr/bin
ln -s /usr/local/sqlite3/bin/sqlite3 sqlite
测试
[root@localhost bin]# sqlite
SQLite version 3.23.1 2018-04-10 17:39:29
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
python3的支持
至此,sqlite可以正常使用,但如果python3想要import引入sqlite3模块是不能识别的。具体错误信息如下:
>>> import sqlite3
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'sqlite3'
>>>
所以,如果想要得到python3的支持,需要重新编译安装python3,这里以python3.6为例,python3.6以上版本是否支持请查看官方文档
python3.6下载地址
https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
python3编译安装【需要添加支持sqlite3参数】
tar xvf Python-3.6.0.tgz
cd Python-3.6.0
./configure LDFLAGS="-L/usr/local/sqlite3/lib" CPPFLAGS="-I /usr/local/sqlite3/include"
make
make install
python3的sqlite3模块导入测试
[root@localhost ~]# python3
Python 3.6.0 (default, Jan 24 2019, 21:08:32)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>>