From 2e39516f204a9d84a473dca183fc2abf9bfedcd0 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 23 Jan 2025 10:29:54 +0000 Subject: [PATCH] Don't use Windows Store python Do not pick the Windows Store python, and clear it from the settings if it was already chosen, as it seems to cause issues on some systems Fixes #127 and #156 --- src/utils/pythonHelper.mts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/utils/pythonHelper.mts b/src/utils/pythonHelper.mts index e2f0cfd4..271ac799 100644 --- a/src/utils/pythonHelper.mts +++ b/src/utils/pythonHelper.mts @@ -11,6 +11,16 @@ import { existsSync } from "fs"; import { homedir } from "os"; import { extensionName } from "../commands/command.mjs"; +function checkUnsupportedPython(pythonPath: string): boolean { + // Problems seem to occur on some Windows systems when using the Windows Store Python + // so check for that and don't use it. + if (pythonPath.includes("AppData\\Local\\Microsoft\\WindowsApps")) { + return true; + } + + return false; +} + /** * This function tries to find a python environment to use. It will possible download * a python environment if it is not found and a download is available. This will @@ -44,7 +54,7 @@ export default async function findPython(): Promise { ); if (pythonPath) { // check if it actually exists and is a supported version - if (existsSync(pythonPath)) { + if (existsSync(pythonPath) && !checkUnsupportedPython(pythonPath)) { try { const version = execSync(`${ process.env.ComSpec === "powershell.exe" ? "&" : "" @@ -210,7 +220,10 @@ async function findPythonInPythonExtension(): Promise { resolved?.version && checkPythonVersion(resolved.version.major, resolved.version.minor) ) { - if (resolved.executable.uri) { + if ( + resolved.executable.uri && + !checkUnsupportedPython(resolved.executable.uri.fsPath) + ) { return resolved.executable.uri.fsPath; } else { Logger.debug( @@ -231,7 +244,10 @@ async function findPythonInPythonExtension(): Promise { resolved?.version && checkPythonVersion(resolved.version.major, resolved.version.minor) ) { - if (resolved.executable.uri) { + if ( + resolved.executable.uri && + !checkUnsupportedPython(resolved.executable.uri.fsPath) + ) { return resolved.executable.uri.fsPath; } else { Logger.debug(