如何在 Visual Studio Code 中调试 Python 3 代码? [英] How can I debug Python 3 code in Visual Studio Code?

查看:80
本文介绍了如何在 Visual Studio Code 中调试 Python 3 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Visual Studio Code 中调试用 Python 3 编写的项目,但我似乎无法在 launch.json 文件中找到任何指定解释器或 Python 版本的方法.

它适用于 Python 2,所以问题是,我如何使它适用于 Python 3?

解决方案

Python 3 调试也很有效.这有点令人困惑,因为有两个不同的地方可以指定路径:settings.jsonlaunch.json.

我建议使用 Don Jayamanne 的 Python 扩展.安装后,您必须配置路径到您想与它一起使用的解释器.

<块引用><块引用>

用于智能感知、自动完成、linting、格式化等的 Python 版本

相同的 Python 解释器用于智能感知、自动完成、linting、格式化等(除调试之外的一切).这使用的标准解释器是第一个 Python 解释器在当前路径中遇到.如果要使用不同的版本,这可以通过以下两种方式之一进行配置:

在用户设置文件中配置python解释器的路径(settings.json) 如下.确保指定完全限定名称的python可执行文件.python.pythonPath":c:/python27/python.exe"

配置Python解释器的路径在工作区设置文件 (settings.json) 中,如下所示.确保指定 Python 可执行文件的完全限定名称.python.pythonPath":c:/python27/python.exe"Python 版本用于调试

可以在此处找到有关调试的配置设置的详细信息调试.只需提供python的完全限定路径python"中的可执行文件配置设置中的设置在launch.json文件中如下:

<代码>{名称":Python",类型":蟒蛇",请求":启动",stopOnEntry":真,程序":${file}",pythonPath":c:/python27/python.exe",调试选项":[等待异常退出",WaitOnNormalExit",重定向输出"]}

I want to debug a project written in Python 3 in Visual Studio Code, but I can't seem to find any way of specifying interpreter or Python version in the launch.json file.

It works great for Python 2, so the question is, how do I make it work for Python 3?

解决方案

Python 3 debugging works well also. It is a little confusing as there are two different places to specify the path: settings.json and launch.json.

I recommend using Don Jayamanne's Python Extension. After installing it, you have to configure the path to the interpreter you want to use it with.

Python Version used for Intellisense, autocomplete, linting, formatting, etc.

The same Python interpreter is used for intellisense, autocomplete, linting, formatting, etc. (everything other than debugging). The standard interpreter used is the first Python interpreter encountered in the current path. If a different version is to be used, this can be configured in one of two ways:

Configure the path to the python interpreter in the User Settings file (settings.json) as follows. Ensure to specify the fully qualified name of the python executable. "python.pythonPath": "c:/python27/python.exe"

Configure the path to the Python interpreter in the Workspace Settings file (settings.json) as follows. Ensure to specify the fully qualified name of the Python executable. "python.pythonPath": "c:/python27/python.exe" Python Version used for debugging

Details on configuration settings for debugging can be found here Debugging. Simply provide the fully qualified path to the python executable in the "python" setting within the configuration settings in the launch.json file as follows:

{
    "name": "Python",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "program": "${file}",
    "pythonPath": "c:/python27/python.exe",
    "debugOptions": [
        "WaitOnAbnormalExit",
        "WaitOnNormalExit",
        "RedirectOutput"
    ]
}

这篇关于如何在 Visual Studio Code 中调试 Python 3 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆