@@ -1107,11 +1107,14 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
11071107 suggestion = _compute_suggestion_error (exc_value , exc_traceback , wrong_name )
11081108 if suggestion :
11091109 self ._str += f". Did you mean: '{ suggestion } '?"
1110- elif exc_type and issubclass (exc_type , ModuleNotFoundError ) and \
1111- sys .flags .no_site and \
1112- getattr (exc_value , "name" , None ) not in sys .stdlib_module_names :
1113- self ._str += (". Site initialization is disabled, did you forget to "
1114- + "add the site-packages directory to sys.path?" )
1110+ elif exc_type and issubclass (exc_type , ModuleNotFoundError ):
1111+ module_name = getattr (exc_value , "name" , None )
1112+ if module_name in sys .stdlib_module_names :
1113+ self ._str = f"Standard library module '{ module_name } ' was not found"
1114+ elif sys .flags .no_site :
1115+ self ._str += (". Site initialization is disabled, did you forget to "
1116+ + "add the site-packages directory to sys.path "
1117+ + "or to enable your virtual environment?" )
11151118 elif exc_type and issubclass (exc_type , (NameError , AttributeError )) and \
11161119 getattr (exc_value , "name" , None ) is not None :
11171120 wrong_name = getattr (exc_value , "name" , None )
0 commit comments