From 2a02e5e7297f8342e83354d935d8efd203b3c399 Mon Sep 17 00:00:00 2001 From: "Lumberbot (aka Jack)" <39504233+meeseeksmachine@users.noreply.github.com> Date: Wed, 29 Jan 2025 12:07:44 -0800 Subject: [PATCH] Backport PR #23377 on branch 6.x (PR: Improve message when a variable can't be viewed due to a missing module (Variable Explorer)) (#23584) --- .../widgets/namespacebrowser.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py b/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py index 2543cd73e29..de75eff96d1 100644 --- a/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py +++ b/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py @@ -19,7 +19,7 @@ from spyder_kernels.comms.commbase import CommError # Local imports -from spyder.config.base import _ +from spyder.config.base import _, is_conda_based_app # For logging logger = logging.getLogger(__name__) @@ -42,6 +42,16 @@ def get_value(self, name): reason_other = _("An unkown error occurred. Check the console because " "its contents could have been printed there") reason_comm = _("The comm channel is not working") + reason_missing_package_installer = _( + "The '{}' package is required to open this variable. " + "Unfortunately, it's not part of our installer, which means your " + "variable can't be displayed by Spyder." + ) + reason_missing_package = _( + "The '{}' package is required to open this variable and it's not " + "installed alongside Spyder. To fix this problem, please install " + "it in the same environment that you use to run Spyder." + ) msg = _("
%s.


" "Note: Please don't report this problem on Github, " "there's nothing to do about it.") @@ -63,6 +73,15 @@ def get_value(self, name): raise except CommError: raise ValueError(msg % reason_comm) + except ModuleNotFoundError as e: + if is_conda_based_app(): + raise ValueError( + msg % reason_missing_package_installer.format(e.name) + ) + else: + raise ValueError( + msg % reason_missing_package.format(e.name) + ) except Exception: raise ValueError(msg % reason_other)