diff -r 94f02193f00f Lib/pydoc.py --- a/Lib/pydoc.py Sat Oct 15 01:18:16 2016 +0000 +++ b/Lib/pydoc.py Sun Oct 16 00:43:20 2016 +0900 @@ -333,7 +333,8 @@ elif exc is SyntaxError: # A SyntaxError occurred before we could execute the module. raise ErrorDuringImport(value.filename, info) - elif exc is ImportError and extract_tb(tb)[-1][2]=='safeimport': + elif exc is ImportError and \ + 'safeimport' in [trace[2] for trace in extract_tb(tb)]: # The import error occurred directly in this function, # which means there is no such module in the path. return None