@@ -15,6 +15,7 @@ import { IPythonExecutionFactory } from '../../common/process/types';
1515import { createDeferred , Deferred } from '../../common/utils/async' ;
1616import * as localize from '../../common/utils/localize' ;
1717import { noop } from '../../common/utils/misc' ;
18+ import { IInterpreterService } from '../../interpreter/contracts' ;
1819import { IJupyterKernelSpec } from '../types' ;
1920import { findIndexOfConnectionFile } from './kernelFinder' ;
2021import { IKernelConnection , IKernelFinder , IKernelLauncher , IKernelProcess } from './types' ;
@@ -46,6 +47,7 @@ class KernelProcess implements IKernelProcess {
4647
4748 constructor (
4849 private executionFactory : IPythonExecutionFactory ,
50+ private interpreterService : IInterpreterService ,
4951 private file : IFileSystem ,
5052 private _connection : IKernelConnection ,
5153 private _kernelSpec : IJupyterKernelSpec
@@ -71,11 +73,17 @@ class KernelProcess implements IKernelProcess {
7173 const pythonPath = this . _kernelSpec . metadata ?. interpreter ?. path || args [ 0 ] ;
7274 args . shift ( ) ;
7375
74- const executionService = await this . executionFactory . create ( {
76+ // Use that to find the matching interpeter.
77+ const matchingInterpreter = await this . interpreterService . getInterpreterDetails ( pythonPath ) ;
78+
79+ // Use that to create an execution service with the correct environment.
80+ const executionService = await this . executionFactory . createActivatedEnvironment ( {
7581 resource : undefined ,
76- pythonPath
82+ interpreter : matchingInterpreter
7783 } ) ;
78- const exeObs = executionService . execObservable ( args , { } ) ;
84+
85+ // Then launch that process, also merging in the environment in the kernelspec
86+ const exeObs = executionService . execObservable ( args , { extraVariables : this . _kernelSpec . env } ) ;
7987
8088 if ( exeObs . proc ) {
8189 exeObs . proc ! . on ( 'exit' , ( exitCode ) => {
@@ -124,6 +132,7 @@ export class KernelLauncher implements IKernelLauncher {
124132 constructor (
125133 @inject ( IKernelFinder ) private kernelFinder : IKernelFinder ,
126134 @inject ( IPythonExecutionFactory ) private executionFactory : IPythonExecutionFactory ,
135+ @inject ( IInterpreterService ) private interpreterService : IInterpreterService ,
127136 @inject ( IFileSystem ) private file : IFileSystem
128137 ) { }
129138
@@ -141,7 +150,13 @@ export class KernelLauncher implements IKernelLauncher {
141150 }
142151
143152 const connection = await this . getKernelConnection ( ) ;
144- const kernelProcess = new KernelProcess ( this . executionFactory , this . file , connection , kernelSpec ) ;
153+ const kernelProcess = new KernelProcess (
154+ this . executionFactory ,
155+ this . interpreterService ,
156+ this . file ,
157+ connection ,
158+ kernelSpec
159+ ) ;
145160 await kernelProcess . launch ( ) ;
146161 return kernelProcess ;
147162 }
0 commit comments