您的当前位置:首页正文

Pycharm远程Linux服务器debug运行时出现:FileNotFoundError: [Errno 2] No such file or directory: ‘/tmp/xxx/...‘

来源:九壹网

0 前言

报错示例如下:

/home/ubuntu/anaconda3/envs/caduceus_env/bin/python /home/ubuntu/.pycharm_helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client localhost --port 35441 --file /tmp/5whGoNXgHh/TTIRI_on_caduceus/main_for_caduceus.py
bash: line 1: cd: /tmp/5whGoNXgHh/TTIRI_on_caduceus: No such file or directory
pydev debugger: warning: trying to add breakpoint to file that does not exist: /tmp/5whGoNXgHh/TTIRI_on_caduceus/main_for_caduceus.py (will have no effect)
Traceback (most recent call last):
File "/home/ubuntu/.pycharm_helpers/pydev/pydevd.py", line 1496, in _exec
pydev_imports.execfile(file, globals, locals)  # execute the script
File "/home/ubuntu/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 11, in execfile
stream = tokenize.open(file)  # @UndefinedVariable
File "/home/ubuntu/anaconda3/envs/caduceus_env/lib/python3.8/tokenize.py", line 392, in open
buffer = _builtin_open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/5whGoNXgHh/TTIRI_on_caduceus/main_for_caduceus.py'

在首行中 “–file /tmp/xxx/…” 指明了将执行的脚本文件,这是在一个临时文件夹下,而不是希望的服务器指定同步项目文件夹下。

在最终解决和修复后,首行中 “–file” 将指向希望的脚本正确路径,控制台将呈现如下的结果,并成功开始Debug…

/home/ubuntu/anaconda3/envs/caduceus_env/bin/python /home/ubuntu/.pycharm_helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client localhost --port 38605 --file /home/ubuntu/jingkz/code/caduceus-main/ttiri_on_caduceus_remote_sync/main_for_caduceus.py 
Running................................................................
CUDA Version: 12.1
Total 1 GPUs available to use!

1 原因分析及解决方案

1.1 原因

1.2 解决方案

在 Run/Debug Configurations 中进行设置运行路径映射,步骤如下:

注意:其中红色框中的是配置的路径映射,也即当前项目路径和服务器指定的项目同步文件夹路径。最后,点击右下角的 ‘Apply’ 和 ‘OK’ 。

这样就可以进行本地 debug 远程代码啦!!!

因篇幅问题不能全部显示,请点此查看更多更全内容

Top