> 文章列表 > vscode-python环境配置

vscode-python环境配置

vscode-python环境配置

vscode-python环境配置

1、环境基础

  1. 下载vscode
  2. 找到python插件并安装
  3. 安装python环境并配置环境变量

2、选择python解释器

尝试执行了一下,直接运行py文件,会使用c++的调试工具,需要告诉vscode哪些是python

  • Ctrl + Shift + P打开命令面板

  • 执行python: Select Interpreter,选择对应的python.exe。vscode会将这个python.exe的路径存储在工作区设置里

3、codeRunner

第二步似乎作用不大,理论上已经可以直接执行了,但是没有

于是在扩展工具里装了一个CodeRunner,进入python文件,右上角run code

执行成功

应该可以不使用CodeRunner执行,我有点嫌弃这个需要点击的编译方式

4、配置文件

  1. 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", // 配置名称,将会在启动配置的下拉菜单中显示  "type": "cppdbg",       // 配置类型,这里只能为cppdbg  "request": "launch",    // 请求配置类型,可以为launch(启动)或attach(附加)  "program": "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径  "args": [],             // 程序调试时传递给程序的命令行参数,一般设为空即可  "stopAtEntry": false,   // 设为true时程序将暂停在程序入口处,一般设置为false  "cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录  "environment": [],  "externalConsole": false, // 调试时是否显示控制台窗口,一般设置为true显示控制台  "MIMode": "gdb",  "miDebuggerPath": "D:/Setting/mingw64/bin/gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应  "preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc  "setupCommands": [  {   "description": "Enable pretty-printing for gdb",  "text": "-enable-pretty-printing",  "ignoreFailures": true  }  ]  }  ]  
    }
    
  2. 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 生成活动文件","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": "调试器生成的任务。"}]
    }