diff --git a/src/notebooks/controllers/kernelSource/localPythonKernelSelector.node.ts b/src/notebooks/controllers/kernelSource/localPythonKernelSelector.node.ts index a9fcb6eb17a..ce124c2ea37 100644 --- a/src/notebooks/controllers/kernelSource/localPythonKernelSelector.node.ts +++ b/src/notebooks/controllers/kernelSource/localPythonKernelSelector.node.ts @@ -103,7 +103,7 @@ export class LocalPythonKernelSelector extends DisposableBase { if (!this.pythonApi || token.isCancellationRequested) { return; } - this.pythonEnvPicker.recommended = findPreferredPythonEnvironment(this.notebook, this.pythonApi); + this.pythonEnvPicker.recommended = findPreferredPythonEnvironment(this.notebook, this.pythonApi, filter); }; const setupApi = (api?: PythonExtension) => { if (!api) { diff --git a/src/notebooks/controllers/preferredKernelConnectionService.node.ts b/src/notebooks/controllers/preferredKernelConnectionService.node.ts index 32c99725d66..9ae3281bf8a 100644 --- a/src/notebooks/controllers/preferredKernelConnectionService.node.ts +++ b/src/notebooks/controllers/preferredKernelConnectionService.node.ts @@ -7,13 +7,18 @@ import { isParentPath } from '../../platform/common/platform/fileUtils'; import { EnvironmentType } from '../../platform/pythonEnvironments/info'; import { getEnvironmentType } from '../../platform/interpreter/helpers'; import { Environment, PythonExtension } from '@vscode/python-extension'; +import type { PythonEnvironmentFilter } from '../../platform/interpreter/filter/filterService'; export function findPreferredPythonEnvironment( notebook: NotebookDocument, - pythonApi: PythonExtension + pythonApi: PythonExtension, + filter: PythonEnvironmentFilter ): Environment | undefined { // 1. Check if we have a .conda or .venv virtual env in the local workspace folder. - const localEnv = findPythonEnvironmentClosestToNotebook(notebook, pythonApi.environments.known); + const localEnv = findPythonEnvironmentClosestToNotebook( + notebook, + pythonApi.environments.known.filter((e) => !filter.isPythonEnvironmentExcluded(e)) + ); if (localEnv) { return localEnv; }