简体   繁体   English

无法在VSCode中调试第一个最简单的Python脚本

[英]Unable to debug first simplest Python script in VSCode

Just installed VS Code 1.20.1 on my Mac OSX 10.13.3 and am following a tutorial on LinkedIn. 刚在我的Mac OSX 10.13.3上安装了VS Code 1.20.1,并且正在关注LinkedIn上的教程。 I'm getting an error when trying to run a simple "Hello World" script, and can't figure out the solution. 尝试运行简单的“ Hello World”脚本时遇到错误,无法解决。

Here's my script, and my launch.json section relevant to this debug run. 这是我的脚本,以及与此调试运行相关的launch.json部分。

#
# Example file for HelloWorld
#

def main():
  print('hello world')

if __name__ == '__main__':
  main()

Screen grab of VSCode Hello World Python script VSCode Hello World Python脚本的屏幕截图

在此处输入图片说明

{
    "name": "Python",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "pythonPath": "${config:python.pythonPath}",
    "program": "${file}",
    "cwd": "",
    "env": {},
    "envFile": "${workspaceFolder}/.env",
    "debugOptions": [
    "RedirectOutput"
    ]
},

My launch.json file 我的launch.json文件

在此处输入图片说明

This is because the program attribute of your launch.json file is set wrong. 这是因为launch.json文件的program属性设置错误。 ${file} (as you set it) tells vscode to use the current file for debugging, so the launch.json . ${file} (根据您的设置)告诉vscode使用当前文件进行调试,所以launch.json So just change that entry to the following: 因此,只需将该条目更改为以下内容:

"program": "${workspaceFolder}/path/to/your/helloworld_start.py"

To get started with python and vscode I would recommend you the official docs . 为了开始使用python和vscode,我建议您使用官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM