From 672d07e673a21108d7e27ce00b894c540efe4c70 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Mon, 6 Mar 2023 11:26:11 -0800 Subject: [PATCH] Do not use `-I` flag in case we're unable to find `encodings` module when validating python (#20803) Closes https://github.com/microsoft/vscode-python/issues/20793 --- .../base/info/environmentInfoService.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client/pythonEnvironments/base/info/environmentInfoService.ts b/src/client/pythonEnvironments/base/info/environmentInfoService.ts index 180e243ae710..d3d3a252c99f 100644 --- a/src/client/pythonEnvironments/base/info/environmentInfoService.ts +++ b/src/client/pythonEnvironments/base/info/environmentInfoService.ts @@ -169,11 +169,16 @@ class EnvironmentInfoService implements IEnvironmentInfoService { return undefined; }); } else if (reason) { - if (reason.message.includes('Unknown option: -I')) { + if ( + reason.message.includes('Unknown option: -I') || + reason.message.includes("ModuleNotFoundError: No module named 'encodings'") + ) { traceWarn(reason); - traceError( - 'Support for Python 2.7 has been dropped by the Python extension so certain features may not work, upgrade to using Python 3.', - ); + if (reason.message.includes('Unknown option: -I')) { + traceError( + 'Support for Python 2.7 has been dropped by the Python extension so certain features may not work, upgrade to using Python 3.', + ); + } return buildEnvironmentInfo(env, false).catch((err) => { traceError(err); return undefined;