diff --git a/jupyterhub/singleuser/__init__.py b/jupyterhub/singleuser/__init__.py index 6addc3b3..dd295377 100644 --- a/jupyterhub/singleuser/__init__.py +++ b/jupyterhub/singleuser/__init__.py @@ -63,9 +63,29 @@ if _as_extension: f"Cannot use JUPYTERHUB_SINGLEUSER_EXTENSION={_extension_env} with JUPYTERHUB_SINGLEUSER_APP={_app_env}." " Please pick one or the other." ) - from .extension import main + try: + from .extension import main + except ImportError as e: + # raise from to preserve original import error + raise ImportError( + "Failed to import JupyterHub singleuser extension." + " Make sure to install dependencies for your single-user server, e.g.\n" + " pip install 'jupyterhub[singleuser]'" + ) from e else: - from .app import SingleUserNotebookApp, main + try: + from .app import SingleUserNotebookApp, main + except ImportError as e: + # raise from to preserve original import error + if _app_env: + _app_env_log = f"JUPYTERHUB_SINGLEUSER_APP={_app_env}" + else: + _app_env_log = "default single-user server" + raise ImportError( + f"Failed to import {_app_env_log}." + " Make sure to install dependencies for your single-user server, e.g.\n" + " pip install 'jupyterhub[singleuser]'" + ) from e # backward-compatibility if SingleUserNotebookApp is not None: diff --git a/jupyterhub/singleuser/_disable_user_config.py b/jupyterhub/singleuser/_disable_user_config.py index 3255e647..3732b4d2 100644 --- a/jupyterhub/singleuser/_disable_user_config.py +++ b/jupyterhub/singleuser/_disable_user_config.py @@ -22,8 +22,6 @@ rather than keeing these monkey patches around. import os from pathlib import Path -from jupyter_core import paths - def _is_relative_to(path, prefix): """ @@ -68,6 +66,10 @@ def _disable_user_config(serverapp): 2. Search paths for extensions, etc. 3. import path """ + # delayed import to avoid triggering early ImportError + # with unmet dependencies + from jupyter_core import paths + original_jupyter_path = paths.jupyter_path() jupyter_path_without_home = list(_exclude_home(original_jupyter_path))