西山區(qū)城市建設(shè)局網(wǎng)站哈市今日頭條最新
vscode-python環(huán)境配置
1、環(huán)境基礎(chǔ)
- 下載vscode
- 找到python插件并安裝
- 安裝python環(huán)境并配置環(huán)境變量
2、選擇python解釋器
嘗試執(zhí)行了一下,直接運(yùn)行py文件,會(huì)使用c++的調(diào)試工具,需要告訴vscode哪些是python
-
Ctrl + Shift + P打開命令面板
-
執(zhí)行
python: Select Interpreter
,選擇對(duì)應(yīng)的python.exe。vscode會(huì)將這個(gè)python.exe的路徑存儲(chǔ)在工作區(qū)設(shè)置里
3、codeRunner
第二步似乎作用不大,理論上已經(jīng)可以直接執(zhí)行了,但是沒有
于是在擴(kuò)展工具里裝了一個(gè)CodeRunner,進(jìn)入python文件,右上角run code
執(zhí)行成功
應(yīng)該可以不使用CodeRunner執(zhí)行,我有點(diǎn)嫌棄這個(gè)需要點(diǎn)擊的編譯方式
4、配置文件
-
launch.json
{ "version": "0.2.0", "configurations": [ {"name": "Python: Current File","type": "python","request": "launch","program": "${file}","python": "D:\\Setting\\Python\\python.exe","args": ["--source"]},{ "name": "(gdb) Launch", // 配置名稱,將會(huì)在啟動(dòng)配置的下拉菜單中顯示 "type": "cppdbg", // 配置類型,這里只能為cppdbg "request": "launch", // 請(qǐng)求配置類型,可以為launch(啟動(dòng))或attach(附加) "program": "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",// 將要進(jìn)行調(diào)試的程序的路徑 "args": [], // 程序調(diào)試時(shí)傳遞給程序的命令行參數(shù),一般設(shè)為空即可 "stopAtEntry": false, // 設(shè)為true時(shí)程序?qū)和T诔绦蛉肟谔?#xff0c;一般設(shè)置為false "cwd": "${workspaceFolder}", // 調(diào)試程序時(shí)的工作目錄,一般為${workspaceFolder}即代碼所在目錄 "environment": [], "externalConsole": false, // 調(diào)試時(shí)是否顯示控制臺(tái)窗口,一般設(shè)置為true顯示控制臺(tái) "MIMode": "gdb", "miDebuggerPath": "D:/Setting/mingw64/bin/gdb.exe", // miDebugger的路徑,注意這里要與MinGw的路徑對(duì)應(yīng) "preLaunchTask": "g++", // 調(diào)試會(huì)話開始前執(zhí)行的任務(wù),一般為編譯程序,c++為g++, c為gcc "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
-
task.json
{"version": "2.0.0","command": "g++","args": ["-g","${file}","-o","${workspaceFolder}/exe/${fileBasenameNoExtension}.exe","-std=c++17","D:/Setting/opencv/build/x64/mingw/bin/libopencv_world460.dll","-I","D:/Setting/opencv/build/x64/mingw/install/include",// "-lprotobuf -lpthread"],"problemMatcher": {"owner": "cpp","fileLocation": ["relative","\\"],"pattern": {"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$","file": 1,"line": 2,"column": 3,"severity": 4,"message": 5}},"tasks": [{"type": "cppbuild","label": "C/C++: g++.exe 生成活動(dòng)文件","command": "D:\\BasicSetting\\mingw64\\bin\\g++.exe","args": ["-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe","-std=c++17","D:/Setting/opencv/build/x64/mingw/bin/libopencv_world460.dll","-I","D:/Setting/opencv/build/x64/mingw/install/include",],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "調(diào)試器生成的任務(wù)。"}] }