配置可執(zhí)行路徑:
"python.pythonPath": "C:\\Users\\LittleTrue\\AppData\\Local\\Programs\\Python\\Python37",
Python 擴(kuò)展還支持不同的代碼分析工具(pep8、flake8、pylint)。要啟用你喜歡的或者正在進(jìn)行的項(xiàng)目所使用的分析工具,只需要進(jìn)行一些簡(jiǎn)單的配置。
這里使用比較靈活的flake8:
ctrl+~ 打開命令行輸入: pip install flake8
在編譯器的setting.json中配置
//python代碼規(guī)范提示 "python.linting.pylintEnabled": false, //這一行是為了禁用python插件建議我們用的pylint "python.linting.enabled": true, "python.linting.flake8Path": "C:\\Users\\LittleTrue\\AppData\\Local\\Programs\\Python\\Python37\\Scripts\\flake8", "python.linting.flake8Enabled": true, "python.linting.flake8Args": [ "--max-line-length=90" ],
可以配置 VS Code 使其自動(dòng)格式化代碼。目前支持 autopep8、black 和 yapf。
要格式化代碼,一般設(shè)置保存時(shí)自動(dòng)格式化就行。
這里使用比較普遍的yapf:
ctrl+~ 打開命令行輸入: pip install yapf
在編譯器的setting.json中配置
//python代碼自動(dòng)規(guī)范 "python.formatting.provider": "yapf", "python.formatting.yapfPath": "C:\\Users\\LittleTrue\\AppData\\Local\\Programs\\Python\\Python37\\Scripts\\yapf", "python.formatting.yapfArgs": [], "editor.formatOnSave": true, "editor.renderIndentGuides": false,
launch.json 文件: 點(diǎn)擊菜單欄調(diào)試 —> 打開配置,就會(huì)彈出一個(gè)選擇框,我們?cè)谶@里要選擇Python,然后就打開并在當(dāng)前目錄生成了launch.json。
tasks.json:點(diǎn)擊菜單欄終端 —> 配置默認(rèn)生成任務(wù),就會(huì)彈出一個(gè)選擇框,選擇已有項(xiàng)目或者新建一個(gè)后, 我們?cè)谶@里要選擇OTHER,然后就打開并在當(dāng)前目錄生成了tasks.json。
launch.json: 指定自定義生成命令和編譯器開關(guān),以及任意(與非生成相關(guān))任務(wù)。
通過“解決方案資源管理器”上下文菜單項(xiàng)“配置任務(wù)”進(jìn)行訪問。
tasks.json: 指定用于調(diào)試的命令行參數(shù)。
通過“解決方案資源管理器”上下文菜單項(xiàng)“調(diào)試和啟動(dòng)設(shè)置”進(jìn)行訪問。
連續(xù)按兩次F5是不是特別不習(xí)慣,沒事,我們來改掉它!
安裝插件Code Runner
安裝后配置
"code-runner.executorMap": {"python": "C:/Users/LittleTrue/AppData/Local/Programs/Python/Python37/python.exe",}
就可以通過F1 --run code 或者ctrl+alt+N直接運(yùn)行
隨時(shí)隨地,F(xiàn)5調(diào)試運(yùn)行。注意,VSCode默認(rèn)在調(diào)試后,會(huì)停在第一句,如下圖。
調(diào)試快捷鍵與VS基本相同。
F5:調(diào)試/繼續(xù),
F10:?jiǎn)尾教^,
F11:?jiǎn)尾竭M(jìn)入,
Shift+F11:跳出。
F9:切換斷點(diǎn)
”stopOnEntry”:true,設(shè)置為false就可以不再暫停在第一句。
修改一下launch.json :參考
調(diào)試步驟:參考
Problems loading reference '[https://schemastore.azurewebsites.net/schemas/json/package.json](https://schemastore.azurewebsites.net/schemas/json/package.json)': Unable to load schema from '[https://schemastore.azurewebsites.net/schemas/json/package.json](https://schemastore.azurewebsites.net/schemas/json/package.json)': Unable to connect to [https://schemastore.azurewebsites.net/schemas/json/package.json](https://schemastore.azurewebsites.net/schemas/json/package.json)
聯(lián)系客服