目 录CONTENT

文章目录

Vscode调试Python踩坑记录

Vscode调试Python踩坑记录

debug时加入参数

打开launch.json文件,向其中添加args参数,一行传参,一行传值

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "${workspace}/main.py",   
      "type": "python",
      "request": "launch",
      "python": "/home/usrname/anaconda3/envs/envs_name/bin/python",
      "args": [
        "--input_path",
        "~/input_path",
      ],      
      "program": "${file}",
      "console": "integratedTerminal"
      "env": {"PYTHONPATH": "${workspaceFolder}/libs/"}
    }
  ]
}

Vscode中python导入包出错

这是由于vscode总是以最上层作为工作目录,如果代码没有在最上层执行,那么就会出现此类错误。

解决方法如上图,添加env参数,给"PYTHONPATH" 赋值"${workspaceFolder}/*****/"

调试方法

按照上面的流程设置好后,不能直接点按debug,需要按Run -> Start Debugging

0

评论区