记录于2021年8月22日
配置好远程的Python解释器后,直接进行Debug使用的仍旧是本地的环境。我们希望的肯定是利用远程服务器进行调试,所以需要进行如下配置:
RunEdit Configurations
左上角+号
Python Debug Server
IDE host name填入本地IP地址(不是服务器的)。
Port填入随便的不用的端口。
Path mappings也非常关键,决定在远程终端中是否能找到程序入口,详情见后文新增内容。
然后在服务器端执行图中指示1(装错版本也会报错):
pip3.6 install pydevd-pycharm==212.4746.96
最后在想要debug的程序中(本地和服务器端同步,加在本地记得查看同步情况)按照指示2加入两句话:
import pydevd
pydevd.settrace('x.x.x.x', port=12345, stdoutToServer=True, stderrToServer=True)
在本地点击Debug,在服务器另一端的命令行中运行相同的程序。
参考文章:https://www.cnblogs.com/jinjiangongzuoshi/p/5638706.html
2021年8月23日新增
RunEdit Configurations
左上角+号
Python Debug Server
在出来的界面中Path mappings的配置非常关键:
之前的配置:
今天出现了报错:
pydev debugger: warning: trying to add breakpoint to file that does not exist: /home/lucifer/CODE/human-motion-prediciton/src/translate.py (will have no effect)
因为是在终端中进入项目目录之后执行的程序
lucifer@lucifer:~$ cd CODE/
lucifer@lucifer:~/CODE$ cd human-motion-prediction/
lucifer@lucifer:~/CODE/human-motion-prediction$ python3.6 src/translate.py
所以在远程终端中找不到了/home/lucifer/CODE/human-motion-prediciton/src/translate.py这个Remote path。
在本地将Remote path修改成src/translate.py即可被终端找到(src前没有/)
总结:在远程终端中会根据本地配置的Remote path找到对应的文件,并进行breakpoint的同步(在本地加入的breakpoint并不会由Deployment同步过去)。