Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 15, 2025

When python.useEnvironmentsExtension is enabled, the Python native REPL was calling getEnvironment(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:

  • Added scope inference logic when getEnvironment() is called with undefined
  • Resolution order:
    1. Active text editor's document URI (if file scheme and not untitled)
    2. Single workspace folder URI (if no active editor)
    3. Global environment (fallback)
async getEnvironment(scope: GetEnvironmentScope): Promise<PythonEnvironment | undefined> {
    let currentScope = checkUri(scope) as GetEnvironmentScope;
    
    if (currentScope === undefined) {
        const activeDoc = activeTextEditor()?.document;
        if (activeDoc && !activeDoc.isUntitled && activeDoc.uri.scheme === 'file') {
            currentScope = activeDoc.uri;
        } else {
            const workspaceFolders = getWorkspaceFolders();
            if (workspaceFolders && workspaceFolders.length === 1) {
                currentScope = workspaceFolders[0].uri;
            }
        }
    }
    
    await waitForEnvManager(currentScope ? [currentScope] : undefined);
    return this.envManagers.getEnvironment(currentScope);
}

Added src/test/features/pythonApi.getEnvironment.unit.test.ts:

  • 7 test cases covering scope resolution edge cases
  • Validates handling of untitled documents, non-file schemes, and multi-workspace scenarios
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 version (& distribution if applicable, e.g. Anaconda): 3.13.0
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): System
  • Value of the python.languageServer setting: Default
User Settings


languageServer: "Pylance"

Installed Extensions
Extension Name Extension Id Version
debugpy ms- 2025.10.0
even-better-toml tam 0.21.2
intellicode-api-usage-examples Vis 0.2.9
java red 1.43.1
js-debug ms- 1.102.0
js-debug-companion ms- 1.1.3
jupyter ms- 2025.6.0
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.3.0
python ms- 2025.10.1
r REd 2.8.6
r-syntax REd 0.1.3
rainbow-csv mec 3.20.0
vscode-gradle vsc 3.16.4
vscode-java-debug vsc 0.58.2
vscode-java-dependency vsc 0.24.1
vscode-java-pack vsc 0.29.2
vscode-java-test vsc 0.43.1
vscode-js-profile-table ms- 1.0.10
vscode-jupyter-cell-tags ms- 0.1.9
vscode-jupyter-slideshow ms- 0.1.6
vscode-maven vsc 0.44.0
vscode-pylance ms- 2025.7.1
vscode-python-envs ms- 1.2.0
vscodeintellicode Vis 1.3.2
System Info
Item Value
CPUs 13th Gen Intel(R) Core(TM) i7-1365U (12 x 2688)
GPU Status 2d_canvas: enabled
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
Load (avg) undefined
Memory (System) 31.67GB (16.35GB free)
Process Argv --crash-reporter-id bad86640-caad-401d-8273-da88a560591e
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
binariesv615:30325510
2e7ec940:31000449
nativeloc1:31344060
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
hdaa2157:31222309
copilot_t_ci:31333650
e5gg6876:31282496
pythoneinst12:31285622
c7cif404:31314491
pythonpulldiag:31343502
996jf627:31283433
pythonrdcb7:31342333
usemplatestapi:31297334
0aa6g176:31307128
747dc170:31275177
aj953862:31281341
generatesymbolt:31295002
convertfstringf:31295003
pylancequickfixf:31350060
9d2cg352:31346308
convertlamdat:31350063
usemarketplace:31343026
nesew2to5:31336538
agentclaude:31335814
nes-diff-11:31337487
replacestringexc:31350595
nes-set-on:31340697
6abeh943:31336334
envsactivate1:31353494
yijiwantestdri0626-c:31336931
0927b901:31350571
ji9b5146:31348712
45650338:31356125
0cj2b977:31352657

<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:
  • with python.useEnvironmentsExtension set to true then the REPL does not use the venv set
  • with python.useEnvironmentsExtension set to `fal...

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 16, 2025 00:06
Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Python native REPL ignoring workspace interpreter Fix getEnvironment API to infer scope from active editor when undefined Dec 16, 2025
Copilot AI requested a review from anthonykim1 December 16, 2025 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python native REPL ignoring workspace interpreter

2 participants