-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Type: Bug
Behaviour
Pylance consistently shows the error "Import "firebase_functions" could not be resolved" for the line import firebase_functions in a main.py file. This occurs when the processsermonaudio folder is opened as a single-root workspace in VS Code.
This happens despite the following conditions being met:
- The project uses a virtual environment (
.venv) located directly within the workspace root (processsermonaudio/.venv/), created with Python 3.13.3.functions-framework(which providesfirebase_functions) is confirmed installed in this venv viapip list. - The VS Code Python interpreter is selected to point to this virtual environment (
...\processsermonaudio\.venv\Scripts\python.exe), and this is reflected in the VS Code status bar and initial Python Output logs as the "Active interpreter." - The workspace setting
python.defaultInterpreterPathinprocesssermonaudio/.vscode/settings.jsonis explicitly set to.\.venv\Scripts\python.exe. - User
settings.jsoncontains no conflicting Python path settings.
Key Observation & Hypothesis:
The Python Output panel logs consistently show that after the Python extension correctly identifies the venv's Python interpreter, it subsequently uses the global Python installation (C:/Users/<UserID>/AppData/Local/Programs/Python/Python313/python.exe) to execute some of its own internal helper scripts (e.g., printEnvVariables.py, printEnvVariablesToFile.py). This behavior was observed with Python extension versions ms-python.python-2025.6.1 and ms-python.python-2025.4.0, and with Pylance versions 2025.5.1 and 2025.4.1.
It's hypothesized that the Pylance error occurs because it relies on environment information gathered by these helper scripts. Since these scripts are run by the global Python, the information does not include the venv's site-packages, leading Pylance to incorrectly conclude firebase_functions is unavailable. The core issue seems to be why the Python extension defaults to global Python for these helper scripts despite a venv being configured.
This might be thematically related to broader interpreter context issues like those discussed in GitHub issue #23448 for the vscode-python repository (though that issue focuses on multi-root workspaces, and this report is for a single-root setup).
Troubleshooting Steps Attempted (without resolution for Pylance error):
- Confirmed
functions-frameworkinrequirements.txtand successful installation in venv. - Ensured
processsermonaudiofolder is the workspace root. - Explicitly selected venv interpreter; set
python.defaultInterpreterPathin workspace settings. - Confirmed User
settings.jsonhas no conflicting Python paths. - Multiple VS Code reloads ("Developer: Reload Window", "Python: Clear Cache and Reload Window").
- Launched VS Code from an external PowerShell directly into the
processsermonaudiodirectory. - Verified workspace trust.
- Confirmed system
PYTHONPATHandPYTHONHOMEare unset/empty, andpyenvis not installed. - Tested with multiple Python extension and Pylance versions (details should be auto-included by the reporter, but specifically Python Extension
2025.6.1&2025.4.0, Pylance2025.5.1&2025.4.1).
Expected Behaviour:
Pylance should resolve imports from packages installed in the selected virtual environment. The Python extension should consistently use the selected virtual environment's Python interpreter for all its internal helper scripts related to environment discovery for that workspace.
Request:
Could you please investigate why the Python extension might use a global Python interpreter to run some of its internal helper scripts even when a virtual environment is properly selected and configured as the active interpreter for the workspace (in a single-root setup)?
Steps to reproduce:
- Setup:
- OS: Windows 11
- Global Python: Python 3.13.3 installed at a path like
C:\Users\<UserID>\AppData\Local\Programs\Python\Python313\python.exe. - VS Code with Python extension and Pylance installed.
- Create Project Structure:
- Create a folder for a Python project (e.g.,
C:\Users\<UserID>\Documents\Projects\SermonFlow\sermonflow-backend\functions\processsermonaudio).
- Create a folder for a Python project (e.g.,
- Open in VS Code:
- Open this
processsermonaudiofolder as a single-root workspace in VS Code.
- Open this
- Create and Activate Virtual Environment:
- In the VS Code terminal, navigate to this folder.
- Create a venv:
python -m venv .venv(using the global Python 3.13.3). - Activate the venv:
.\.venv\Scripts\Activate.ps1.
- Install Dependencies:
- Create
requirements.txtinprocesssermonaudiowith the content:firebase-admin functions-framework
- In the activated venv terminal, run
pip install -r requirements.txt. Verifyfunctions-frameworkinstalls.
- Create
- Configure VS Code Interpreter:
- Use "Python: Select Interpreter" command to choose
.\.venv\Scripts\python.exefrom the current workspace. - Optionally, create
.vscode/settings.jsoninprocesssermonaudiowith:{ "python.defaultInterpreterPath": "./.venv/Scripts/python.exe" } - Reload VS Code window.
- Use "Python: Select Interpreter" command to choose
- Create Python File:
- Create
main.pyinprocesssermonaudiowith the content:import firebase_functions # Pylance error expected here print("firebase_functions imported?")
- Create
- Observe Behaviour:
- Pylance flags
import firebase_functionswith "Import "firebase_functions" could not be resolved". - Check the "Python" Output panel for logs showing the pattern of global Python usage for helper scripts.
- Pylance flags
Diagnostic data
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
2025-05-21 06:02:04.256 [info] Experiment 'pythonRecommendTensorboardExt' is active
2025-05-21 06:02:04.257 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2025-05-21 06:02:04.257 [info] Native locator: Refresh started
2025-05-21 06:02:04.257 [info] Native locator: Refresh started
2025-05-21 06:02:04.257 [info] > pyenv which python
2025-05-21 06:02:04.257 [info] cwd: .
2025-05-21 06:02:09.393 [info] Python interpreter path: .\.venv\Scripts\python.exe
2025-05-21 06:02:09.711 [info] Native locator: Refresh finished in 23678 ms
2025-05-21 06:02:17.661 [info] Starting Pylance language server.
2025-05-21 06:02:19.243 [info] > & ./.venv/Scripts/Activate.ps1 ; echo 'e8b39361-0157-4923-80e1-22d70d46dee6' ; python ~/.vscode/extensions/ms-python.python-2025.4.0-win32-x64/python_files/printEnvVariables.py
2025-05-21 06:02:19.245 [info] shell: powershell
2025-05-21 06:02:37.585 [info] > ~\AppData\Local\Programs\Python\Python313\python.exe ~/.vscode/extensions/ms-python.python-2025.4.0-win32-x64/python_files/printEnvVariables.py
2025-05-21 06:02:37.586 [info] shell: powershell
2025-05-21 06:03:00.286 [info] Prepending environment variable PATH in collection with c:\Users\<UserID>\.vscode\extensions\ms-python.python-2025.4.0-win32-x64\python_files\deactivate\powershell;C:\Users\<UserID>\Documents\Projects\SermonFlow\sermonflow-backend\Functions\processSermonAudio\.venv\Scripts; {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-05-21 06:03:00.287 [info] Setting environment variable VIRTUAL_ENV in collection to C:\Users\<UserID>\Documents\Projects\SermonFlow\sermonflow-backend\Functions\processSermonAudio\.venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-05-21 06:03:00.287 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to .venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-05-21 06:03:00.295 [info] Send text to terminal: & C:/Users/<UserID>/AppData/Local\Programs\Python\Python313\python.exe c:\Users\<UserID>\.vscode\extensions\ms-python.python-2025.4.0-win32-x64\python_files\printEnvVariablesToFile.py c:\Users\<UserID>\.vscode\extensions\ms-python.python-2025.4.0-win32-x64\python_files\deactivate\powershell\envVars.txt
Extension version: 2025.4.0
VS Code version: Code 1.100.2 (848b80aeb52026648a8ff9f7c45a9b0a80641e2e, 2025-05-14T21:47:40.416Z)
OS version: Windows_NT x64 10.0.26100
Modes:
- Python version (& distribution if applicable, e.g. Anaconda): 3.13.3
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
- Value of the
python.languageServersetting: Default
User Settings
languageServer: "Pylance"
Installed Extensions
| Extension Name | Extension Id | Version |
|---|---|---|
| azure-repos | ms- | 0.40.0 |
| cloudcode | goo | 2.30.0 |
| copilot | Git | 1.322.0 |
| copilot-chat | Git | 0.27.1 |
| debugpy | ms- | 2025.4.1 |
| docker | doc | 0.6.0 |
| geminicodeassist | goo | 2.33.0 |
| gitlens | eam | 17.1.0 |
| js-debug | ms- | 1.100.1 |
| js-debug-companion | ms- | 1.1.3 |
| LiveServer | rit | 5.7.9 |
| prettier-vscode | esb | 11.0.0 |
| python | ms- | 2025.4.0 |
| remote-containers | ms- | 0.413.0 |
| remote-repositories | ms- | 0.42.0 |
| remotehub | Git | 0.64.0 |
| vscode-docker | ms- | 1.29.6 |
| vscode-js-profile-table | ms- | 1.0.10 |
| vscode-pylance | ms- | 2025.4.1 |
System Info
| Item | Value |
|---|---|
| CPUs | Intel(R) Pentium(R) Silver N5030 CPU @ 1.10GHz (4 x 1094) |
| 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) | 3.83GB (0.47GB free) |
| Process Argv | . --crash-reporter-id 579effca-e82b-405e-b7df-54752692650d |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
c4g48928:30535728
azure-dev_surveyone:30548225
2i9eh265:30646982
962ge761:30959799
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dwnewjupyter:31046869
pythonrstrctxt:31112756
nativeloc1:31192215
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
hdaa2157:31222309
copilot_t_ci:31222730
e5gg6876:31282496
pythoneinst12:31285622
bgtreat:31268568
4gafe986:31271826
c7cif404:31309971
pythonpulldiagcf:31298646
996jf627:31283433
pythonrdcb7:31303018
usemplatestapi:31297334
0aa6g176:31307128
7bj51361:31289155
747dc170:31275177
pylancecolorcf:31309109
aj953862:31281341
generatesymbolt:31295002
convertfstringf:31295003
gendocf:31295004
j6a0c355:31309728