1 回答

TA貢獻1866條經驗 獲得超5個贊
為什么沒有安裝模塊
沒有安裝 requirements.txt 文件中指定的模塊,因為 launch.json 中沒有對tasks.json的引用。要在執行 python 應用程序之前執行任務,需要"preLaunchTask": "pipInstall"引用pipInstalltasks.json 中命名的任務。
修改后的代碼
注意:我還修復了一些不正確的路徑并將我的虛擬環境移動到我的項目之外的新目錄。
設置.json
{
"python.pythonPath": "C:\\thepath\\.venv\\Scripts\\python.exe"
}
啟動.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\batch-python-quickstart\\src\\python_quickstart_client.py",
"console": "integratedTerminal",
"preLaunchTask": "pipInstall"
}
]
}
任務.json
{
"version": "2.0.0",
"tasks": [
{
"label": "pipInstall",
"type": "shell",
"osx": {
"command": "${config:python.pythonPath}/bin/python -m pip install -r requirements.txt"
},
"windows": {
"command": "${config:python.pythonPath} -m pip install -r requirements.txt"
},
"linux": {
"command": "${config:python.pythonPath}/bin/python -m pip install -r requirements.txt"
},
"problemMatcher": [],
"options": {
"cwd": "${workspaceFolder}\\batch-python-quickstart\\src"
}
}
]
}
此外
可以通過在任務中添加相同的依賴屬性來級聯任務;"dependsOn": "othertasklabel". 一組構建步驟的理想選擇。
添加回答
舉報