vscode如何远程调试python代码

您所在的位置:网站首页 python没有bin文件 vscode如何远程调试python代码

vscode如何远程调试python代码

2023-05-11 20:42| 来源: 网络整理| 查看: 265

环境配置配置 python 环境

准备一段 python 代码

from __future__ import print_function def sum_nums(n): s=0 for i in range(n): s += i print(s) if __name__ == '__main__': sum_nums(5)登录后复制

然后在左侧运行和调试按钮中,点击“创建launch.json”文件,选择 python文件(如果没有的话需要先安装 python 扩展,在应用中搜索 python 第一个安装了最多的即可)

选择 python 文件

生成默认的 launch 文件如下

{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: 当前文件", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true } ] }登录后复制

这里我们需要自定义指定一下用到的 python 版本,需要添加 “pythonPath” 选项

{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: 当前文件", "type": "python", "pythonPath": "/home/lthpc/anaconda3/bin/python3.7", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true } ] }登录后复制

这样的话就可以使用指定的 python 运行代码了

如果说用到了 conda 虚拟环境,则需要找到虚拟环境对应的 python 路径,可以使用 whereis python 查看

调试代码

配置好调试环境后,在代码中打上断点,然后点击运行调试和执行按钮,即可进入调试页面

以上就是vscode如何远程调试python代码的详细内容,更多请关注php中文网其它相关文章!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3