目录

vscodecursor配置python环境,含远程调试

vscode(cursor)配置python环境,含远程调试

一、本地配置

1.1 安装python插件

https://i-blog.csdnimg.cn/direct/20d7889d9adb427d8aa4f16769decfc1.png

1.2 配置python环境

在右下角就可以切换python环境,太简单了!

https://i-blog.csdnimg.cn/direct/81c52976d25f463dbc1e5b0fca083c83.png

1.3 Debug说明

打断点直接开启!

https://i-blog.csdnimg.cn/direct/d8ab3968c2244cc2b45c2cfc8fbc8de1.png

在debug的过程中,还可以输入打印中间变量或者做一些测试

https://i-blog.csdnimg.cn/direct/60b28b638fa04851b949bd93d8f7ab12.png

二、远程连接

2.1 下载远程工具

https://i-blog.csdnimg.cn/direct/ca0ff64225a14aad8cad5e84107067b7.png

2.2 连接远程

下载后出现,这个图标,然后连接输入密码即可:

https://i-blog.csdnimg.cn/direct/8abf2cb5fe404b3ebbaed80710a1f3ba.png

2.3 安装python插件

远端仍然要安装python插件

2.3 设置当前路径

代码里配置路径

2.4 远程访问免密

2.5 设置运行脚本参数

根目录下: .vscode/launch.json

如果没有就选择debug栏点这个配置:

https://i-blog.csdnimg.cn/direct/4b3d8a518fc1431392a7eaca671de92a.png

  • launch.json 的内容
{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Python: 当前文件",
        "type": "debugpy",
        "request": "launch",
        "program": "libs/chatchat-server/chatchat/cli.py", # 运行文件
        "console": "integratedTerminal",
        "cwd": "/xxx/codes/langchain-chatchat-0.3.0",  # 工作目录
        "justMyCode": true,
        "args": ["start", "-a"]  # 运行参数
      }
    ]
  }

然后点运行:

https://i-blog.csdnimg.cn/direct/5db36282d9a14c249fe2573fb1cb1301.png

2.6 设置环境变量

仍然是在前面的 launch.json 中增加内容:

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Python: 当前文件",
        "type": "debugpy",
        "request": "launch",
        "program": "cli.py",
        "console": "integratedTerminal",
        "cwd": "/xxx/codes/langchain-chatchat-0.3.0/libs/chatchat-server/chatchat",  
        "justMyCode": true,
        "args": ["start", "-a"],
        "env": {
                "CHATCHAT_ROOT": "/xxx/codes/langchain-chatchat-0.3.0/libs/chatchat-server/chatchat/data"
        } # 这里则是增加环境变量
      }
    ]
  }

然后仍然按照上述方式启动即可。

2.7 调试怎么看module里面的东西

“justMyCode”: true, ==> false

2.8 如何格式化python代码

需要安装插件autopep8