Skip to content

Commit 47ba376

Browse files
improve ModuleNotFoundError when -S is passed
1 parent 3a64844 commit 47ba376

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Lib/traceback.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,10 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
11061106
suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name)
11071107
if suggestion:
11081108
self._str += f". Did you mean: '{suggestion}'?"
1109+
elif exc_type and issubclass(exc_type, ModuleNotFoundError) and \
1110+
sys.flags.no_site:
1111+
self._str += ". Site initialization is disabled, did you forget to add the \
1112+
site-package directory to sys.path?"
11091113
elif exc_type and issubclass(exc_type, (NameError, AttributeError)) and \
11101114
getattr(exc_value, "name", None) is not None:
11111115
wrong_name = getattr(exc_value, "name", None)
@@ -1286,7 +1290,7 @@ def format_exception_only(self, *, show_group=False, _depth=0, **kwargs):
12861290
def _find_keyword_typos(self):
12871291
assert self._is_syntax_error
12881292
try:
1289-
import _suggestions
1293+
import _suggestions # type: ignore
12901294
except ImportError:
12911295
_suggestions = None
12921296

0 commit comments

Comments
 (0)