VSCode remote debugging python

Configuration

1. Enter the corresponding docker and conda environment of the server
2. Install debugpy pip install debugpy
3. Click the debug button in VSCode
Insert image description here
4. Follow the prompts to install extension
Insert image description here
5 and configure
Insert image description here
Insert image description here
Insert image description here
the final launch.json file launch.json:

{
    
    
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
    
    
            "name": "Python: 远程附加",
            "type": "python",
            "request": "attach",
            "connect": {
    
    
                "host": "0.0.0.0",
                "port": 5678
            },
            "pathMappings": [
                {
    
    
                    "localRoot": "/xxx/peft/src", // test.py文件目录
                    "remoteRoot": "."
                }
            ],
            "justMyCode": true
        }
    ]
}

debugging

6. Terminal operation

python -m debugpy --listen 0.0.0.0:5678 --wait-for-client test.py

7. Set breakpoints and click the run button to debug
Insert image description here
Insert image description here

question

1. I want to debug peft-related code. Do not put the test.py script in the peft directory. Because the peft code uses a relative path to import, an error will be reported: The ImportError: attempted relative import with no known parent package
directory structure is as follows:

|- peft
	|- src
		|- test.py
		|- peft
			|- __init__.py
			|- ...

Zhihu: python relative import common problems and solutions

Guess you like

Origin blog.csdn.net/dragonchow123/article/details/132742197