Open
Description
Type: Bug
Behaviour
When declaring that the default Python interpeter is a .bat
file (and switching to that environment), VSCode seems to pick up Intellisense correctly but when using Ctrl + Shift + P -> Run Python File in terminal, it uses an "evaluated" path to the python.exe
file instead of the .bat
file.
However, because the .bat
file is setting up crucial environment variables, using the direct python.exe
path fails to run any scripts at all.
This is critical when trying to run Python scripts meant for QGIS' python version.
Steps to reproduce:
- Install QGIS (3.40 LTR) (https://qgis.org/download/)
- You should now have
C:/Program Files/QGIS 3.40.7/bin/python-qgis-ltr.bat
- Create a new folder, open it in VSCode, create the
.vscode/settings.json
file as
{
"python.defaultInterpreterPath": "C:/Program Files/QGIS 3.40.7/bin/python-qgis-ltr.bat"
}
- Create a file
minimal_init.py
from qgis.core import QgsApplication
QgsApplication.setPrefixPath("C:\\Program Files\\QGIS 3.40.7\\apps")
qgs = QgsApplication([], GUIenabled=False)
qgs.initQgis()
print("QGIS init OK")
qgs.exitQgis()
- Try to run the script via Ctrl+Shift+P -> Run Python File in Terminal
- Observe failed output
> & "C:/Program Files/QGIS 3.40.7/bin/python.exe" "c:/Users/Max Gerhardt/temp/xxxxxxxx/minimal_init.py"
Traceback (most recent call last):
File "c:\Users\Max Gerhardt\temp\xxxxxxxx\minimal_init.py", line 1, in <module>
from qgis.core import QgsApplication
ModuleNotFoundError: No module named 'qgis'
- Observe expected output if using the
.bat
file correctly
> & 'C:\Program Files\QGIS 3.40.7\bin\python-qgis-ltr.bat' .\minimal_init.py
QGIS init OK
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-06-12 16:21:51.478 [info] Send text to terminal: & "C:/Program Files/QGIS 3.40.7/bin/python.exe" "c:/Users/Max Gerhardt/temp/xxxxxxxxxxxxxxxx/webserver.py"
2025-06-12 16:27:08.606 [info] Experiment 'pythonaa' is active
2025-06-12 16:27:08.606 [info] Experiment 'pythonRecommendTensorboardExt' is active
2025-06-12 16:27:08.606 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2025-06-12 16:27:08.607 [info] Native locator: Refresh started
2025-06-12 16:27:08.607 [info] Native locator: Refresh started
2025-06-12 16:27:10.242 [info] > pyenv which python
2025-06-12 16:27:10.242 [info] cwd: c:\Users\Max Gerhardt\temp\xxxxxxxxxxxxxxxx
2025-06-12 16:27:11.026 [info] Python interpreter path: C:\Program Files\QGIS 3.40.7\bin\python.exe
2025-06-12 16:27:11.229 [info] Native locator: Refresh finished in 2830 ms
2025-06-12 16:27:13.470 [info] Starting Pylance language server.
2025-06-12 16:27:14.580 [error] Active interpreter type is detected as Unknown {"id":"C:\\Program Files\\QGIS 3.40.7\\bin\\python.exe","sysPrefix":"C:\\Program Files\\QGIS 3.40.7\\apps\\Python312","envType":"Unknown","envName":"","envPath":"C:\\Program Files\\QGIS 3.40.7\\bin\\python.exe","path":"C:\\Program Files\\QGIS 3.40.7\\bin\\python.exe","architecture":3,"sysVersion":"","version":{"raw":"3.12.10","major":3,"minor":12,"patch":10,"build":[],"prerelease":[]},"displayName":"Python 3.12.10","detailedDisplayName":"Python 3.12.10"}
2025-06-12 16:46:12.096 [info] Discover tests for workspace name: xxxxxxxxxxxxxxxx - uri: c:\Users\Max Gerhardt\temp\xxxxxxxxxxxxxxxx\minimal_init.py
2025-06-12 16:46:16.580 [info] Send text to terminal: & "C:/Program Files/QGIS 3.40.7/bin/python.exe" "c:/Users/Max Gerhardt/temp/xxxxxxxxxxxxxxxx/minimal_init.py"
2025-06-12 16:46:49.909 [info] Discover tests for workspace name: xxxxxxxxxxxxxxxx - uri: c:\Users\Max Gerhardt\temp\xxxxxxxxxxxxxxxx\minimal_init.py
2025-06-12 16:46:51.530 [info] Discover tests for workspace name: xxxxxxxxxxxxxxxx - uri: c:\Users\Max Gerhardt\temp\xxxxxxxxxxxxxxxx\minimal_init.py
Extension version: 2025.6.1
VS Code version: Code 1.100.3 (258e40fedc6cb8edf399a463ce3a9d32e7e1f6f3, 2025-06-02T13:30:54.273Z)
OS version: Windows_NT x64 10.0.19045
Modes:
- Python version (& distribution if applicable, e.g. Anaconda): 3.12.10
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Unknown
- Value of the
python.languageServer
setting: Default
User Settings
envFile: "<placeholder>"
languageServer: "Pylance"
Installed Extensions
Extension Name | Extension Id | Version |
---|---|---|
cpptools | ms- | 1.25.3 |
debugpy | ms- | 2025.8.0 |
hexeditor | ms- | 1.11.1 |
js-debug | ms- | 1.100.1 |
js-debug-companion | ms- | 1.1.3 |
platformio-ide | pla | 3.3.4 |
python | ms- | 2025.6.1 |
vscode-js-profile-table | ms- | 1.0.10 |
vscode-pylance | ms- | 2025.5.1 |
System Info
Item | Value |
---|---|
CPUs | AMD Ryzen 7 PRO 5850U with Radeon Graphics (16 x 1896) |
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) | 59.83GB (25.04GB free) |
Process Argv | --crash-reporter-id f4192565-3aa4-4705-8793-f5cca82f9e4f |
Screen Reader | no |
VM | 50% |
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
binariesv615:30325510
vscaac:30438847
c4g48928:30535728
azure-dev_surveyone:30548225
vscrp:30673768
2i9eh265:30646982
962ge761:30959799
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:31000557
dwnewjupyter:31046869
pythonrstrctxt:31112756
nativeloc1:31192215
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
9064b325:31222308
copilot_t_ci:31222730
e5gg6876:31282496
pythoneinst12:31285622
bgtreat:31268568
4gafe986:31271826
c7cif404:31314491
pythonpulldiagcf:31325931
996jf627:31283433
pythonrdcb7:31303018
usemplatestapi:31297334
0aa6g176:31307128
7bj51361:31289155
747dc170:31275177
6518g693:31325878
pylancecolor:31314202
aj953862:31281341
generatesymbolt:31295002
convertfstringf:31295003
gendocf:31295004