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

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

问题描述

我想在Visual Studio代码中调试用python3编写的项目,但是似乎没有找到任何方法在launch.json文件中指定解释器或python版本。



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

解决方案

p> Python3调试也很好。这有点混乱,因为有两个不同的地方指定路径: settings.json launch.json 。我建议您使用 Don Jayamanne的Python Extension 。安装完毕后,您必须将路径配置为口译员你要使用它。



用于智能感知,自动完成,粘贴,格式化等的Python版本


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



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



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



调试配置设置的详细信息可以在这里找到
调试。只需在launch.json文件中的配置设置
中的python设置中提供python
可执行文件的完全限定路径,如下所示:




  {
name:Python,
type:python,
:启动,
stopOnEntry:true,
程序:$ {file},
pythonPath:c:/python27/python.exe
debugOptions:[
WaitOnAbnormalExit,
WaitOnNormalExit,
RedirectOutput
]}
/ pre>

I want to debug a project written in python3 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?

解决方案

Python3 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代码中调试Python3代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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