vscode 调试 python程序

一、配色

文件-首选项-颜色主题-浅色/默认浅色

二、远程连接服务器

1.下载插件remoteSSH

2.配置config文件

.ssh/config

Host ldif
  HostName 10.7.28.47
  User root
  Port 2022

三、Debug

下载插件python,然后创建launch.json

launch.json

{
    
    
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
    
    
            "python": "/root/anaconda3/envs/CAD/bin/python3.7",
            "name": "json2mesh",
            "type": "python",
            "request": "launch",
            "program": "/root/DeepCAD/dataset/json2mesh.py",
            "console": "integratedTerminal",
            "env": {
    
    
                "CUDA_VISIBLE_DEVICES": "2,3"
            },
            "args": [
                "--only_test"
            ]
        },
     ]
 }

https://blog.csdn.net/weixin_39278265/article/details/107705492

带有 -m 参数

我在命令行运行的是python3 -m sosed.run -i input_examples/input.txt -o
output/closure/,但是在VSCode中的普通调试,会报模块找不到的问题(原因是普通调试不会带-m参数,所以有些路径就会找不到)。

在命令行运行:

# 先按照这个module
python3 -m pip install debugpy 

# 在命令行运行:
python3 -m debugpy --listen 5678 --wait-for-client  -m sosed.run -i input_examples/input.txt -o output/closure/

而后在VSCode中

点击:上方菜单栏->debug->Open Configurations,修改内容为如下:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Attach",
            "type": "python",
            "request": "attach",
            "connect": {
            "host": "localhost",
            "port": 5678
            }
        }
    ]
}

四、自动进入环境

修改/root/.bashrc文件
最后一行添加 source activate name

猜你喜欢

转载自blog.csdn.net/weixin_42785537/article/details/120509617