Missing module sqlite3 when running Jupyterhub on Rocky9

I’m trying to install Jupyterhub for my users on a Rocky9 Linux system. Most of the installation went fine. There were no errors for the following commands:

useradd -m -c 'Runs the JupyterHub server' jupyterhub
passwd -l jupyterhub
su - jupyterhub
python3.12 -m venv jupyterhub-env
source jupyterhub-env/bin/activate
pip install jupyterhub notebook configurable-http-proxy

Then, generate a configuration file, which is ~/jupyterhub_config.py

jupyterhub --generate-config

I only changed the port number in the config file.

Finally, I started the server:

jupyterhub
[I 2024-08-21 15:55:29.320 JupyterHub app:3307] Running JupyterHub version 5.1.0
[I 2024-08-21 15:55:29.320 JupyterHub app:3337] Using Authenticator: jupyterhub.auth.PAMAuthenticator-5.1.0
[I 2024-08-21 15:55:29.320 JupyterHub app:3337] Using Spawner: jupyterhub.spawner.LocalProcessSpawner-5.1.0
[I 2024-08-21 15:55:29.320 JupyterHub app:3337] Using Proxy: jupyterhub.proxy.ConfigurableHTTPProxy-5.1.0
[I 2024-08-21 15:55:29.326 JupyterHub app:1837] Loading cookie_secret from /home/jupyterhub/jupyterhub_cookie_secret
[E 2024-08-21 15:55:29.342 JupyterHub app:3873]
    Traceback (most recent call last):
      File "/home/jupyterhub/jupyterhub-env/lib/python3.12/site-packages/jupyterhub/app.py", line 3870, in launch_instance_async
        await self.initialize(argv)
      File "/home/jupyterhub/jupyterhub-env/lib/python3.12/site-packages/jupyterhub/app.py", line 3349, in initialize
        self.init_db()
      File "/home/jupyterhub/jupyterhub-env/lib/python3.12/site-packages/jupyterhub/app.py", line 2009, in init_db
        self.session_factory = orm.new_session_factory(
                               ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/jupyterhub/jupyterhub-env/lib/python3.12/site-packages/jupyterhub/orm.py", line 1564, in new_session_factory
        engine = create_engine(url, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<string>", line 2, in create_engine
      File "/home/jupyterhub/jupyterhub-env/lib/python3.12/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
        return fn(*args, **kwargs)  # type: ignore[no-any-return]
               ^^^^^^^^^^^^^^^^^^^
      File "/home/jupyterhub/jupyterhub-env/lib/python3.12/site-packages/sqlalchemy/engine/create.py", line 599, in create_engine
        dbapi = dbapi_meth(**dbapi_args)
                ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/jupyterhub/jupyterhub-env/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 508, in import_dbapi
        from sqlite3 import dbapi2 as sqlite
      File "/usr/local/lib/python3.12/sqlite3/__init__.py", line 57, in <module>
        from sqlite3.dbapi2 import *
      File "/usr/local/lib/python3.12/sqlite3/dbapi2.py", line 27, in <module>
        from _sqlite3 import *
    ModuleNotFoundError: No module named '_sqlite3'

I googled for solutions, but came up empty, so I hope someone here can help.

Thanks in advance!

Scott Anderson

In a rockylinux:9 container:

# dnf install python3.12
...

# which python3.12
/usr/bin/python3.12

If I copy your commands I end up with a working JupyterHub.

It looks like you’re using a non-standard version of Python under /usr/local:

Is it possible your Python isn’t correctly installed, or has somehow become corrupted due to conflicting packages?

It’s certainly possible that I made a mistake in installing Python 3.12. I followed these directions: CrownCloud Wiki - How To Install Python 3 12 On RockyLinux 9

but only recently, so not a lot of people have used the Python 3.12 yet.

I’ll try Python 3.9, which Rocky9 came with.

Thanks for the suggestion!

Using the Python 3.9 worked fine, so suspicion now falls on the Python 3.12. Thanks for the suggestion!

installing Python from source has a number of ‘optional’ dependencies that shouldn’t really be optional, and are available in ~all Python installations except some manual ones. sqlite is one of them. To install python from source, make sure you have sqlite-devel before compiling Python:

dnf install sqlite-devel

You can also look in the (very long) output of compiling Python for hints about missing optional dependencies.

Thank you! I’ll look into that. It’s good to know that I might not have botched the installation; it might just need some additions.

Scott