配置可執行路徑:
"python.pythonPath": "C:\\Users\\LittleTrue\\AppData\\Local\\Programs\\Python\\Python37",
Python 擴展還支持不同的代碼分析工具(pep8、flake8、pylint)。要啟用你喜歡的或者正在進行的項目所使用的分析工具,只需要進行一些簡單的配置。
這里使用比較靈活的flake8:
ctrl+~ 打開命令行輸入: pip install flake8
在編譯器的setting.json中配置
//python代碼規范提示 "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 使其自動格式化代碼。目前支持 autopep8、black 和 yapf。
要格式化代碼,一般設置保存時自動格式化就行。
這里使用比較普遍的yapf:
ctrl+~ 打開命令行輸入: pip install yapf
在編譯器的setting.json中配置
//python代碼自動規范 "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 文件: 點擊菜單欄調試 —> 打開配置,就會彈出一個選擇框,我們在這里要選擇Python,然后就打開并在當前目錄生成了launch.json。
tasks.json:點擊菜單欄終端 —> 配置默認生成任務,就會彈出一個選擇框,選擇已有項目或者新建一個后, 我們在這里要選擇OTHER,然后就打開并在當前目錄生成了tasks.json。
launch.json: 指定自定義生成命令和編譯器開關,以及任意(與非生成相關)任務。
通過“解決方案資源管理器”上下文菜單項“配置任務”進行訪問。
tasks.json: 指定用于調試的命令行參數。
通過“解決方案資源管理器”上下文菜單項“調試和啟動設置”進行訪問。
連續按兩次F5是不是特別不習慣,沒事,我們來改掉它!
安裝插件Code Runner
安裝后配置
"code-runner.executorMap": {"python": "C:/Users/LittleTrue/AppData/Local/Programs/Python/Python37/python.exe",}
就可以通過F1 --run code 或者ctrl+alt+N直接運行
隨時隨地,F5調試運行。注意,VSCode默認在調試后,會停在第一句,如下圖。
調試快捷鍵與VS基本相同。
F5:調試/繼續,
F10:單步跳過,
F11:單步進入,
Shift+F11:跳出。
F9:切換斷點
”stopOnEntry”:true,設置為false就可以不再暫停在第一句。
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)