docker remote interpreter and matplotlib
Answered
I am start to using docker remote interpreter. Everything works great except it seems the SciView no longer showing output of matplotlib. Do I missing some thing or this is a feature not support yet?
same project, by using local interpreter (virtualenv) when I run the code, I will see plot graph on "SicView"
by switch to a remote Docker interpreter, when I run the code, I only see output with "exit code 0", plot is not showing on "SicView"
Please sign in to leave a comment.
Hi Rui Vapps, PyCharm doesn't support showing plots with Docker-based interpreters. Here's a relevant comment: https://youtrack.jetbrains.com/issue/PY-18102#focus=streamItem-27-1412306-0-0
Thanks !
Pavel: does this limitation applies to the case when PyCharm runs on Linux (Ubuntu), and the docker interpreter runs as a local image?
It seems that the limitation does apply as I can't get matplotlib to display, but wanted to double check!
Thanks!
one workaround which solved my problems was this: https://youtrack.jetbrains.com/issue/PY-27489
on linux you can get around this issue by adding adding `-e DISPLAY` and `-v /tmp/.X11-unix:/tmp/.X11-unix` to the configuration
@Linushn93
Could you please explain your fix more detailed? Where did you add these options? Does linux have to be the same version (ie. local os is ubuntu 18.04 -> docker os is ubuntu 18.04 too?)
Thanks in advance!
Go to your run configurations (top right corner) -> edit configurations -> docker configuration and set DISPLAY to :0 (or whatever it is on your system) in the environment variables and map /tmp/.X11-unix to /tmp/.X11-unix to the volumes. I don't know if there are any version requirements (I am using ubuntu 16 on both the host and container)
One addition to the answer by @Linushn93. You should use host networking for the container. This way PyCharm will display figures in SciView.
In case anybody wants a step by step explanation to solve this issue and be able to use Matplotlib while using Pycharm as IDE and docker as interpreter. [This post is based on the answer by @Linushn93] [It works on Ubuntu 16.04 (and probably for several other distributions of the Linux)]
1. First step is to make sure that your Docker interpreter is configured properly. Make sure that you are able to run your code using Docker interpreter (except those that are plotting something, of course!)
2. Go to Run/debug configurations dialog and click on Edit Configurations
3. Open Docker Container Settings
4. Do all these settings here:
- put host in the Network mode (as Gleb Sizov mentioned in his response)
- add a Volume boundings like in the picture (/tmp/.X11-unix to /tmp/.X11-unix)
- add an entry like the following picture to the Environmental variables section (Name is DISPLAY and Value is :0)
Are you expecting more? That's is, have fun with the rest of your project :))
One of my plots after making it work.
[@alisaaalehi]
Hello!
Same problem again.
There no 'network mode' In pycharm professional 2020.1
So, problem looks like
```
Error: failed to send plot to http://127.0.0.1:63342
```
It's pretty obvious problem, but I cannot figure out how to fix it.
I tried to bind 63342 host and docker ports, but then I got error:
"Error starting userland proxy: listen tcp 127.0.0.1:63342: bind: address already in use"
Ok, pycharm listen to 63342.
Any idea how to fix it?
In the "Run options:" you should add
--network "host"
and don't bind any port
This link worked pretty well for me: https://perpetum.de/2021/01/14/how-to-run-pycharm-with-docker-and-conda/
If you want to view matplotlib charts from Docker based interpreter in PyCharm's SciView - here is my workaround:
First, forward the SciView's port (63342) from localhost to the local Docker interface (172.17.0.1) using a tool like Socat:
It will hang till you kill it with Ctrl+C, so run it in a separate terminal.
Then, in the Python console, before you start using Matplotlib, run:
And that's it. Enjoy! :)
PS:
The mysterious datalore package is from the PyCharm helpers volume, which is automatically attached to your container and added to Python path. Do NOT install it with pip.
This package is imported by the backend_interagg package as you can see here:
https://github.com/JetBrains/intellij-community/blob/master/python/helpers/pycharm_matplotlib_backend/backend_interagg.py
The HOST variable is defined here:
https://github.com/JetBrains/intellij-community/blob/master/python/helpers/pycharm_display/datalore/display/display_.py
I've posted a PR to add an environment variable:
https://github.com/JetBrains/intellij-community/pull/2157
PPS:
In case of remote interpreter, just replace 172.17.0.1 with your local machine's IP address.