Skip to content

Commit

Permalink
Don't use Windows Store python
Browse files Browse the repository at this point in the history
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
  • Loading branch information
will-v-pi committed Jan 23, 2025
1 parent 3761deb commit 2e39516
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/utils/pythonHelper.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,7 +54,7 @@ export default async function findPython(): Promise<string | undefined> {
);
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" ? "&" : ""
Expand Down Expand Up @@ -210,7 +220,10 @@ async function findPythonInPythonExtension(): Promise<string | undefined> {
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(
Expand All @@ -231,7 +244,10 @@ async function findPythonInPythonExtension(): Promise<string | undefined> {
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(
Expand Down

0 comments on commit 2e39516

Please sign in to comment.