vscode如何远程调试python代码
作者:BrightSoul
时间:2023-04-29
浏览:3
环境配置配置python环境准备一段python代码from__future__importprint_functiondefsum_nums(n):s=0foriinrange(n):s+=iprint(s)if__name__=='__main__':sum_nums(5)然后在左侧运行和调试按钮中,点击“创建launch.json”文件,选择python文件(如果没有的话需要先安装python扩展,在应用中搜索python第一个安装了最多的即可)选择python文件生成默认的laun
环境配置
配置 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 查看
调试代码
配置好调试环境后,在代码中打上断点,然后点击运行调试和执行按钮,即可进入调试页面
作者最新文章
索尼 Xperia 1 VIII / VII / VI 等手机获 Android 17 更新,新增桌面模式等功能
2026-09-08 16:44
加拿大留学监护声明书(IMM 5646)双页签署与公证核对指南
2026-09-03 15:02
在线PDF转图片教程:一键生成高清图片包
2026-09-03 12:04
Creo零基础入门:新建零件与第一次拉伸建模完整指南
2026-09-03 06:02
扫描件PDF转Word的在线操作步骤与编辑可行性判断
2026-09-02 18:39
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多










































