@@ -5,7 +5,6 @@ import { commands, Disposable, Event, EventEmitter, Uri } from 'vscode'
55import { traceError , traceLog } from './log'
66import { PythonExtension , ResolvedEnvironment } from '@vscode/python-extension'
77import path from 'path'
8- import { IS_WINDOWS } from '../isWindows'
98
109export interface IInterpreterDetails {
1110 path ?: string [ ]
@@ -39,15 +38,16 @@ export async function initializePython(
3938 api . environments . onDidChangeActiveEnvironmentPath ( async e => {
4039 const environment = await api . environments . resolveEnvironment ( e . path )
4140 const isVirtualEnv = environment ?. environment !== undefined
42- const binPath = isVirtualEnv
43- ? environment ?. environment ?. folderUri . fsPath
41+ // Get the directory of the Python executable for virtual environments
42+ const pythonDir = environment ?. executable . uri
43+ ? path . dirname ( environment . executable . uri . fsPath )
4444 : undefined
4545
4646 onDidChangePythonInterpreterEvent . fire ( {
4747 path : [ e . path ] ,
4848 resource : e . resource ?. uri ,
4949 isVirtualEnvironment : isVirtualEnv ,
50- binPath,
50+ binPath : isVirtualEnv ? pythonDir : undefined ,
5151 } )
5252 } ) ,
5353 )
@@ -76,17 +76,16 @@ export async function getInterpreterDetails(
7676 )
7777 if ( environment ?. executable . uri && checkVersion ( environment ) ) {
7878 const isVirtualEnv = environment . environment !== undefined
79- const binPath = isVirtualEnv
80- ? environment . environment ?. folderUri . fsPath
81- : undefined
79+ // Get the directory of the Python executable
80+ const pythonDir = path . dirname ( environment ?. executable . uri . fsPath )
8281
8382 return {
8483 path : [ environment ?. executable . uri . fsPath ] ,
8584 resource,
8685 isVirtualEnvironment : isVirtualEnv ,
87- binPath : binPath
88- ? path . join ( binPath , IS_WINDOWS ? 'Scripts' : 'bin' )
89- : undefined ,
86+ // For virtual environments, we need to point directly to the bin directory
87+ // rather than constructing it from the environment folder
88+ binPath : isVirtualEnv ? pythonDir : undefined ,
9089 }
9190 }
9291 return { path : undefined , resource }
0 commit comments