Pycharm Remote interpreter on Docker remote: [Errno 2] No such file or directory

半世苍凉 提交于 2020-03-22 07:15:32

问题


As specified in the title I am trying to use Pycharm Professional (2018.2) with a python remote interpreter in a Docker machine hosted on a remote server in my LAN. I created a very simple example by following the help 'https://www.jetbrains.com/help/pycharm/using-docker-as-a-remote-interpreter.html'.

  • Pycharm 2018.2 is installed on a LAN pc (192.168.1.10) on a debian distro;
  • Docker is installed on a LAN debian server (192.168.1.22)

I was able to configure Docker as a remote interpreter, to connect with the Docker service through the Pycharm tool but when I try to run (or debug) the main.py in the Docker container I always get this:

37073edcd9d2:python -u /opt/project/main.py (null): can't open file '/opt/project/main.py': [Errno 2] No such file or directory
Process finished with exit code 2

The execution is certainly done in the remote Docker container but it seems that the file to be executed is not found. I manually attached the local volume as described on various blogs with all possible variations but I always get the same error. These are some specifications of my configuration: docker tool setting

project interpreter setting

Run/Debug Configuration

docker container setting with volume mapping into Run/Debug Configuration

Is missing something?

Tanks. Any help is appreciated!


回答1:


The problem lies in the Pycharm 'limit' of managing a docker machine on a remote host 'under the hood'. When inserting the volume mapping in the run / debug configuration, it is interpreted as a local path and therefore, in this case, a path that must be present on the remote server. So, for now, the only option is to mount the local path (the folder where the project is located) on the remote host of the Docker service by first sharing it through an SSHFS or NFS service. So ... (1) I shared the Pycharm project folder (local machine ip 192.168.1.10) using NFS; (2) I mounted the shared folder on the server host (on server ip 192.168.1.22; mount -t nfs 192.168.1.10:/home/user/PythonProjects /home/ext-user/mnt/projects) then (3) in the run / debug configuration of Pycharm I mapped the volumes with the path mounted on the remote server ... Run ... the program now runs without any errors. [Run result]

These are some specifications of my new configuration:

Run/Debug Configuration

docker container setting with volume mapping into Run/Debug Configuration

I hope the solution can be useful to other people. I also hope that there are better solutions than mine :-)



来源:https://stackoverflow.com/questions/52341979/pycharm-remote-interpreter-on-docker-remote-errno-2-no-such-file-or-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!