'No such file or directory' error when trying to Run from Windows PyCharm on Linux Docker

Answered

Hello.

I have set up Docker on my Windows 10 (company) laptop, and now I would like to run the stuff that I code, inside PyCharm. However, I have gone through many setup and problem solving topics on StackOverflow and here too, but can't see any issue with my Docker / Run Configuration in Pycharm.

I have created new Interpreter under my project. daemon is enbled on docker side. On Pycharm, I have set it to "Docker for Windows". In path mappings, I have added path where are the files of the project (that is mapped into docker volume in *.yml file). Virtual machine path is the path where are the files in Docker filesystem (I can access them when I open Docker console). Local path is where the (project) files are on my Windows machine. Connection to Docker seems working, because PyCharm does load the enviroment info, (python version and packages).

Now, in project, I have set interpreter to "Remote Python Docker bla bla bla .." 

In "Run/Debug Configuration" I have set:

Script path: Windows machine path to script that I want to run

Project was pre set.

Python Interpreter: "Remote Python Docker bla bla bla .."  (the one I set up above)

Working directory: Path to the directory, where the script I want to run is, in the Docker filesystem

Path mapping: Local path: The path of the project files on my Windows machine | Remote path: The path of the project files on Docker filesystem.

 

And thats pretty much it. I have been trying different paths mapping. Also, I have had error: "Error running 'hello_w': Cannot run the remote Python interpreter: the working directory 'C:<my path>' is invalid, it needs to be an absolute path" But that one I have solved by changing Windows path in "Working directory" under "Run/Debug Configuration" to a Docker filesystem path.

When I open Docker command line, and run there the command that PyCharm says is running: "python3 -u <my_path>/hello_w.py". It works. But when PyCharms runs it, it gets error:

c3cdf3a9875d:python3 -u /<path>/hello_w.py
python3: can't open file '/<path>/hello_w.py': [Errno 2] No such file or directory

Process finished with exit code 2



Can please anybody give me some hint, about what I am doing wrong? I do python devel on linux for few years already, but I am completely new to Windows environment and Docker too. :)

0
4 comments

Hi,

Could you remove the run configuration, then right-click the file that you want to run and choose Run... from the context menu?
Does it work?

0

Tried that just now, but still same result.

0

Does it give "No such file..." error or that the path should be absolute?

Could you share a screenshot showing your Docker interpreter path mappings and your run configuration?

0

I have found the problem, and "fixed" it. Will explain.

In my devel directory, I have several folders with libraries, while each of them is one project (obviously).

Lets say, it looks like this:

~/dev_dir/project_a/
project_b/
project_c/
project_d/

What I did was, I opened `project_a` in PyCharm. Than opened b, c and d, and added them to current Window by clicking on "Attach".

Did some changes, and decided to try out Docker connection. So I have created remote Docker interpreter under project_a, which was opened.

However, after a while, I have decided that I don't want to mess with live project, so I have created new project `~/dev_dir/project_3_test/`. Openend it and "Attach" to currently opened PyCharm. Created hello word file there and the issues I have described started.

Now, the problem was, tat even if I created new Remote interpreter under project_e_test, and new Run/Debug Config for the `hello_word` file. The "Run / Debug Configurations > Python > wello_word > Execution > Docker container settings: were still mapped to:

--entrypoint -v C:/dev_dir/project_a/:/opt/project --rm

Even if I changed Path mappings, Work directory, Path mappings under Python interpreter in project. It still stays same, there is still path to the project A in this command (which cannot be edited), even if the remote interpreter is created under other projects.

 

1

Please sign in to leave a comment.