microsoft / microsoft/vscode-python-debugger
Could not find platform independent libraries <prefix> when debugging tests in VS Code
还没有人认领这个 Issue。
- 主要语言
- TypeScript
- 星标
- 181
- 派生
- 126
- 平均合并
- 2 天 3 小时
- 30 天内合并 PR
- 3
描述
I'm trying to write a plugin for QGIS and some tests:
import os
import sys
import unittest
from qgis.core import QgsVectorLayer
class Whatever(unittest.TestCase):
def test_1(self):
print(f"PATH: { os.environ["PATH"] }")
print(f"PYTHONPATH: { os.environ["PYTHONPATH"] }")
print(f"PYTHONHOME: { os.environ["PYTHONHOME"] }")
print(f"Executable: { sys.executable }")
layer = QgsVectorLayer("mylayer")
I also have a launch.json like this one:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Debug Tests",
"type": "debugpy",
"request": "launch",
"console": "integratedTerminal",
"purpose": ["debug-test"],
"cwd": "${workspaceFolder}",
"envFile": "${workspaceFolder}/.env"
}
]
}
and a settings.json:
{
"python.defaultInterpreterPath": "C:/OSGeo4W/bin/python.exe",
"python.analysis.extraPaths": [
"C:/OSGeo4W/apps/qgis-ltr/python"
],
"python.analysis.autoImportCompletions": true,
"python.autoComplete.extraPaths": ["C:/OSGeo4W/apps/qgis-ltr/python"],
"python.testing.unittestArgs": [
"-v",
"-s",
"tests/",
"-p",
"*test.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
and finally my .env-file:
PYTHONHOME=C:/OSGeo4W/apps/Python312
PYTHONPATH=C:/OSGeo4W/apps/qgis-ltr/python
PATH=C:/OSGeo4W/apps/qgis-ltr/bin;C:/OSGeo4W/apps/qt5/bin;C:/OSGeo4W/apps/Python312/Scripts;C:/OSGeo4W/bin;C:/Windows/system32;C:/Windows;C:/Windows/system32/WBem
GDAL_DATA=C:/OSGEO4W/share/gdal
GDAL_DRIVER_PATH=C:/OSGEO4W/bin/gdalplugins
GDAL_FILENAME_IS_UTF8=YES
GS_LIB=C:/OSGeo4W/apps/gs/lib
GEOTIFF_CSV=C:/OSGEO4W/share/epsg_csv
O4W_QT_BINARIES=C:/OSGEO4W/apps/Qt5/bin
O4W_QT_DOC=C:/OSGEO4W/apps/Qt5/doc
O4W_QT_HEADERS=C:/OSGEO4W/apps/Qt5/include
O4W_QT_LIBRARIES=C:/OSGEO4W/apps/Qt5/lib
O4W_QT_PLUGINS=C:/OSGEO4W/apps/Qt5/plugins
O4W_QT_PREFIX=C:/OSGEO4W/apps/Qt5
O4W_QT_TRANSLATIONS=C:/OSGEO4W/apps/Qt5/translations
OSGEO4W_ROOT=C:/OSGeo4W
QT_PLUGIN_PATH=C:/OSGEO4W/apps/qgis-ltr/qtplugins
QT_QPA_PLATFORM=windows:altgr
QGIS_PREFIX_PATH=C:/OSGEO4W/apps/qgis
QGIS_PLUGINPATH=D:/git/QgisPlugIns
When I click on the gutter within the test-explorer to debug the above test, I get the forementioned error. However when I just run the test, everything works fine. I already duplictaed the variables from the env-file to the launch.json-file without any success.
I also tried to put these variables into the settings.json-file into the "terminal.integrated.env.windows-section and started a python-interpreter in the terminal. I wrote this script:
from qgis.core import QgsVectorLayer
and it worked. So afterall I can confirm the above paths are 100% correct. However I cannot make it to have them work in both Test-Explorer and in the Terminal. Having them in env-file only makes terminal break ("ImportError: DLL load failed while importing _core: The specified module could not be found". This error relates to the QgsVectorLayer-import-statement), having them in the settings.json only makes test-explorer break. Having them in both leads to "Invalid message: Found duplicate in "env": PATH".
This is my VS Code version:
Version: 1.106.3
Commit: bf9252a2fb45be6893dd8870c0bf37e2e1766d61
Date: 2025-11-25T22:28:18.024Z
Electron: 37.7.0
ElectronBuildId: 12781156
Chromium: 138.0.7204.251
Node.js: 22.20.0
V8: 13.8.258.32-electron.0
OS: Windows_NT x64 10.0.26100
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用提供的 launch.json、settings.json 和 .env,通过 VS Code Test Explorer 重现该故障,并比较调试测试环境与普通测试环境。首先跟踪调试测试启动时环境变量的组装方式;完成的标准是:测试使用 QGIS Python 环境进行调试,同时普通测试运行和终端导入仍能在没有重复 PATH 条目的情况下正常工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python, vscode
- 领域
- devtools, testing
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 35/100