ERPnext v15 Update fails with "No module named '_sqlite3'"

Dear all,

for the first time in years the update a minor update of our ERPnext v15 installation failed. Update runs smoothly at first like always but then crashes when starting to patch sites:

...
Patching sites…
Traceback (most recent call last):
File “/usr/local/lib/python3.10/runpy.py”, line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File “/usr/local/lib/python3.10/runpy.py”, line 86, in _run_code
exec(code, run_globals)
File “/home/erp/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 114, in
main()
File “/home/erp/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 20, in main
click.Group(commands=commands)(prog_name=“bench”)
File “/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1442, in call
return self.main(*args, **kwargs)
File “/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1363, in main
rv = self.invoke(ctx)
File “/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1830, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1830, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1226, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 794, in invoke
return callback(*args, **kwargs)
File “/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/decorators.py”, line 34, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/erp/frappe-bench/apps/frappe/frappe/commands/init.py”, line 29, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/erp/frappe-bench/apps/frappe/frappe/commands/site.py”, line 678, in migrate
from frappe.migrate import SiteMigration
File “/home/erp/frappe-bench/apps/frappe/frappe/migrate.py”, line 24, in
from frappe.search.website_search import build_index_for_all_routes
File “/home/erp/frappe-bench/apps/frappe/frappe/search/init.py”, line 6, in
from frappe.search.sqlite_search import SQLiteSearch
File “/home/erp/frappe-bench/apps/frappe/frappe/search/sqlite_search.py”, line 8, in
import sqlite3
File “/usr/local/lib/python3.10/sqlite3/init.py”, line 23, in
from sqlite3.dbapi2 import *
File “/usr/local/lib/python3.10/sqlite3/dbapi2.py”, line 27, in
from _sqlite3 import *
ModuleNotFoundError: No module named ‘_sqlite3’

Can anyone suggest a recovery strategy?

Hi,

You can verify the sqlite3 module is missing using bench –(sitename) console , then import sqlite3.

Try bench setup requirements as a possible repair.

Thank you, smino, for your reply!

It turned out that for some reason my python binary no longer was able to access its built in sqlite3 library. Reinstalling that fixed the root cause and made the update run smoothly again.

Best,
smw