簡體   English   中英

如何通過 launch.json 在 VS 代碼中將參數傳遞給 python 解釋器(而不是 python 代碼)

[英]How to pass an argument to the python interpreter (not to the python code) in VS code via launch.json

我想將“-q -X faulthandler”arguments 傳遞給 VS code launch.json 中的 python 解釋器,但我還沒有找到解決方案(args 將參數傳遞給 .py 文件)。

所以命令在終端中看起來像這樣:

python** -q -X faulthandler** main.py --arg1 --arg2

謝謝!

我已經閱讀了 VS 代碼文檔,但沒有找到任何相關描述。 我嘗試使用以下 lauch.json 選項在 VS 代碼中執行 python 腳本(均無效):

1、"type": "python -q -X faulthander ", "cwd": "${workspaceRoot}", "request": "launch", "program": "main.py",

2、"type": "python", "cwd": "${workspaceRoot}", "request": "launch", "program": " -q -X faulthandler main.py",

根據官方文檔,在launch.json中可以添加pythonArgs配置來為解釋器指定參數。

另一種方式是安裝Code Runner擴展,然后在設置中搜索Code-runner: Custom Command來自定義執行命令。

在此處輸入圖像描述

或者直接在settings.json中添加如下配置也有同樣的效果。

    "code-runner.customCommand": "python $fileName",

配置完成后,使用Ctrl + Shift + P --> Run: Cunstom Command ( Ctrl + Alt + K ) 執行代碼。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM