3

I'm trying to get a working version of Python 3.7 on CentOS, and the sticking point seems to be the built-in sqlite3 module.

I'm building Python as follows (using a Dockerfile here for reproducibility):

FROM centos:7.6.1810
RUN yum update -y
RUN yum install -y epel-release
RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm

RUN yum install -y python34u python34u-pip
RUN yum install -y python35u python35u-pip
RUN yum install -y python36u python36u-pip

# Python3.7 is not currently available from RHEL, EPEL, or IUS repos so download and compile it
RUN yum install -y gcc openssl-devel bzip2-devel libffi-devel make
ARG PY37_VERSION=3.7.6
RUN cd /usr/src && curl https://www.python.org/ftp/python/${PY37_VERSION}/Python-${PY37_VERSION}.tgz | tar -xz &&\
  cd Python-${PY37_VERSION} && LD_RUN_PATH=/usr/lib ./configure --enable-optimizations && make -j4 altinstall &&\
  rm -rf /usr/src/Python-${PY37_VERSION}
RUN cd /tmp && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3.7 get-pip.py

When I fire up the container and try to import the sqlite3 module, I get a library error:

[root@ccea19dd0dc6 /]# python3.7 -c 'import sqlite3'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.7/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/lib/python3.7/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

Is a solution for this known?

Ken Williams
  • 163
  • 1
  • 9
  • Does sys.path contain `/usr/local/lib/python3.7/lib-dynload/` and is there something like `_sqlite3.cpython-37m-x86_64-linux-gnu.so` in it? – Mark Wagner Jan 10 '20 at 19:33
  • Hi @MarkWagner, `sys.path` contains `/usr/local/lib/python3.7/lib-dynload`, but there are no sqlite-related objects in it. – Ken Williams Jan 10 '20 at 23:19

1 Answers1

3

I poked around a bit in the setup.py file for the python distribution, it looks like it checks in /usr/include for sqlite files. I installed sqlite-devel before building python, looks like that does the trick:

RUN yum install -y gcc openssl-devel bzip2-devel libffi-devel make sqlite-devel
ARG PY37_VERSION=3.7.6
RUN cd /usr/src && curl https://www.python.org/ftp/python/${PY37_VERSION}/Python-${PY37_VERSION}.tgz | tar -xz &&\
  cd Python-${PY37_VERSION} && ./configure --enable-optimizations && make -j4 altinstall &&\
  rm -rf /usr/src/Python-${PY37_VERSION}

Now sqlite3 can be loaded:

[root@b2ae4f2bc5af Python-3.7.6]# python3.7 -c "import sqlite3"
[root@b2ae4f2bc5af Python-3.7.6]#
Ken Williams
  • 163
  • 1
  • 9