19

My question is much like several others. Having manually compiled Python, sqlite3 is missing:

enter image description here

The main difference is that I'm using a Debian Linux system (unlike in this question: OS X 10.8.2 python 3 import sqlite error), and Python3 (unlike in this and a bunch of other questions: Cannot import SQLite with Python 2.6).

I was hoping for some guidance on which direction to troubleshoot in. According to some of the Linux-but-older-Python questions, an error like the one I'm getting could be caused by a missing resource during linking or something (_sqlite3.so). I have two such files on my system, both of them in older Python installations, ... but nothing related to Python3. Or is one of these good enough? Or they say to install the libsqlite3-dev package, then to re-compile Python. I did this, but I don't see how just having this package on my system will affect the compilation process. And indeed, it didn't. A second compile gave me a second Python without sqlite3.

I wish I could just do apt-get install python3, but Debian, in its stability, only has Python 3.2, where I need the latest version. Thoughts?

Community
  • 1
  • 1
Brian Peterson
  • 2,800
  • 6
  • 29
  • 36

3 Answers3

24

You need to install libsqlite3 (Debian based) or sqlite-devel (RedHat based) and the associated header files before compiling Python because Python needs to find them during the compile process.

Did you make sure to run:

  1. ./configure
  2. make
  3. make install

In this specific order? With no missing steps?

shakaran
  • 10,612
  • 2
  • 29
  • 46
Thomas Orozco
  • 53,284
  • 11
  • 113
  • 116
  • How do I make Python find them during the compile process? I mentioned that I had tried installing that exact package. – Brian Peterson Sep 11 '13 at 20:47
  • @Bepetersn I was updating the answer, can you check you did follow those three steps? If it still doesn't work, can you show any warnings that show up during the compile process? – Thomas Orozco Sep 11 '13 at 20:49
  • 2
    @Bepetersn the key step here is `./configure`. You should check its output for sqlite3. – Thomas Orozco Sep 11 '13 at 20:50
  • When I complied python 2.7 by hand on RHEL6, the compiler would crash while trying to build the sqlite3 module due to a 64-bit error and a typedef. (Not sure where I found that link) Try compiling python again, and look very closely at the output and see why (I think) the sqlite module is crashing during compilation. – gregb212 Sep 11 '13 at 20:51
  • "checking for --enable-loadable-sqlite-extensions... no": This is the only reference to sqlite from ./configure's output. I'm `make install`ing right now. – Brian Peterson Sep 11 '13 at 20:56
  • 1
    @Bepetersn For future reference, `configure` is the step that searches for available libraries. Header files (those contained in the `-dev` package) are files that tell the compiler how to build against the sqlite binaries that are on your system. – Thomas Orozco Sep 11 '13 at 20:59
  • I'm on raspberry pi with Raspbian (debian-based distribution) and I already had the following package installed libsqlite3-0, but it did not help and python did not build _sqlite3 library. But after I installed: libsqlite3-dev, it did. I thought this would help somebody out there. – gogaman Feb 17 '16 at 13:06
  • You need to install libsqlite3-dev on Ubuntu 16.04. – Seunghoon Apr 12 '18 at 06:12
19

After apt-get install libsqlite3-dev

then

./configure --prefix=/opt/python3.7.4 --with-ssl --with-pydebug

make
make install

Note: You might need apt-get install libssl-dev aslo, openssl version must above 1.0.2 if you are compiling python3.7

For me, I'm using ubuntu 14.04 (trusty) I can't find a libssl-dev package to meet the requirement compiling python3.7 with ssl support. I modify my /etc/apt/sourcelist.d

deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted

after install a newer libssl-dev, then change it back to the original one

deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted
wukong
  • 2,430
  • 2
  • 26
  • 33
  • 1. --with-ssl seems not required now 2. libffi-dev is aslo required, otherwise there will be an error "No module named '_ctypes' when using Value from module multiprocessing" when `make install` – wukong Oct 28 '20 at 09:42
3

If you only have limited user access (no root or sudo permission) you can install to a local, user accessible, environment like so:

tar -xvf sqlite-autoconf-3270200.tar.gz
cd sqlite-autoconf-3270200
./configure --prefix=$HOME/.local
make && make install

This will install on your ~/.local tree.

Add ~/.local/bin to your path if missing.

QT-1
  • 900
  • 14
  • 21