Fix getEnvironment API to infer scope from active editor when undefined #1067
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
python.useEnvironmentsExtensionis enabled, the Python native REPL was callinggetEnvironment(undefined)but receiving the global interpreter instead of the workspace's selected environment. This caused REPL sessions to ignore project-specific virtual environments.Changes
Modified
src/features/pythonApi.ts:getEnvironment()is called withundefinedAdded
src/test/features/pythonApi.getEnvironment.unit.test.ts:Original prompt
This section details on the original issue you should resolve
<issue_title>Python native REPL ignoring workspace interpreter</issue_title>
<issue_description>
Type: Bug
After updating VS Code today, the Python native REPL no longer uses the selected Python interpreter/virtual environment for the workspace. Instead it always uses the global default interpreter path (which you can see by running
sys.executable). This is a problem because I need the native REPL to use virtual environments for specific projects.Extension version: 2025.10.1
VS Code version: Code 1.102.2 (c306e94f98122556ca081f527b466015e1bc37b0, 2025-07-22T12:15:48.520Z)
OS version: Windows_NT x64 10.0.26100
Modes:
python.languageServersetting: DefaultUser Settings
Installed Extensions
System Info
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
A/B Experiments
<agent_instructions>There should be some api from environment extension maybe in apiLegacy.ts that would allow us to use interpreter selection from environment extension when useEnvironmentExtension is true.
We need to investigate and figure out what is the code path that is not respecting user's selected interpreter path when launching and running code via native REPL. Think deep, investigate thorough. </agent_instructions>
Comments on the Issue (you are @copilot in this section)
@anthonykim1 Do you get different behavior when you add `python.useEnvironmentsExtension": false,` to your settings.json @anthonykim1 I think there has been some changes to `getActiveInterpreter` to use new environment extension API recently. /cc @eleanorjboyd Can you guys try with `python.useEnvironmentsExtension` to true, with the latest pre-release of env extension? We want this to work regardless of env extension presence. @eleanorjboyd thanks for the investigation here- transferring over and Ill take a look @eleanorjboyd Hm @jevogel and @matthewgson I feel like you are seeing opposite things? To clarify:python.useEnvironmentsExtensionset totruethen the REPL does not use the venv setpython.useEnvironmentsExtensionset to `fal...💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.