Running vCD Cli fail with the following error: ModuleNotFoundError: No module named ‘_sqlite3’

After installing the VMware Container Service Extension, which install the vCD CLI in the process, vCD CLI kept failing to start and complaining about not finding sqlite3 module as showing below.  I was installing on CentOS 8.1, but even then it sounds like the sqlite version included with CentOS is out of date for what vCD CLI require to be installed. Below is what the error looked like.

# vcd --help
Traceback (most recent call last):
  File "/home/rohan/.local/lib/python3.7/site-packages/vcd_cli/browsercookie/", line 18, in <module>
    from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/rohan/.local/bin/vcd", line 6, in <module>
    from vcd_cli.vcd import vcd
  File "/home/rohan/.local/lib/python3.7/site-packages/vcd_cli/", line 121, in <module>
    from vcd_cli import login  # NOQA
  File "/home/rohan/.local/lib/python3.7/site-packages/vcd_cli/", line 24, in <module>
    from vcd_cli import browsercookie
  File "/home/rohan/.local/lib/python3.7/site-packages/vcd_cli/browsercookie/", line 20, in <module>
    import sqlite3
  File "/usr/local/lib/python3.7/sqlite3/", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/lib/python3.7/sqlite3/", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

While the steps below is mainly focused on how to fix the issue to be able to install vCD or CSE, the same steps will be relevant to anyone having a similar ModuleNotFoundError: No module named ‘_sqlite3’ error in Python to install any other application.

At a high level, the steps I had to follow to fix the issue is:

  1. Upgrade the CentOS system install of SQLite to version 3.31.1 by compiling it from source. Make sure to use the ./configure –prefix=/usr to upgrade the system version. You must include the Prefix or it will install to /usr/local instead by default which is not what we want.
[root@vtcse01 Python-3.7.3]# wget
[root@vtcse01 Python-3.7.3]# tar xvf sqlite-autoconf-3310100.tar.gz
[root@vtcse01 Python-3.7.3]# cd sqlite-autoconf-3310100/
[root@vtcse01 Python-3.7.3]# ./configure --prefix=/usr
[root@vtcse01 Python-3.7.3]# make install

2. Confirm the system SQLite version is upgraded to 3.31.1 as expected using sqlite3 --version
[root@vtcse01 Python-3.7.3]# sqlite3 –version
3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516eaa837bb4d6

3. Re-compile Python 3.7.x. Be sure run "make clean" before "make install" if you've already installed it.
[root@vtcse01 ~]# wget
[root@vtcse01 ~]# tar xvf Python-3.7.3.tgz
[root@vtcse01 ~]# cd Python-3.7*/
[root@vtcse01 Python-3.7.3]# ./configure --enable-optimizations
[root@vtcse01 Python-3.7.3]# make install
[root@vtcse01 Python-3.7.3]# python3.7 --version;
Python 3.7.3
[root@vtcse01 Python-3.7.3]# pip3.7 --version
Check below that Python3.7.3 is detecting your updated sqllite
4. Open python3.7, import sqlite3, followed by sqlite3.sqlite_version to check SQLite version.
[root@vtcse01 Python-3.7.3]# python3
Python 3.7.3 (default, May  4 2020, 15:36:31)
[GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version

Python 3.7.x import SQLite3

Now that Python 3.7.x and SQLite 3.31.1 is properly installed you can proceed with your vCD CLI or CSE as usual and it should pass that stage! Hope this help you resolve your issue and save some time.