New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QXcbConnection: Could not connect to display #10627
Comments
Can you check that I guess it might be matplotlib picking a different backend, though I'm not sure why it would do that. |
Right-- I forgot to mention that I'm running this on a cluster head node that doesn't have a display. So there is no $DISPLAY set ( |
And if I explicitly set the backend to |
Are you using the IPython terminal interface or IPython as a kernel in a Jupyter interface? I think IPython as a kernel sets the |
I was just using the ipython terminal interface. It would seem that if a |
@tacaswell any idea why IPython might be affecting the default backend here? |
This happens because the default backend for Matplotlib in Anaconda is Qt5. We're considering to change it to Tk to avoid this kind of problems. |
Changing to Tk would still have the same problem. I think it is showing up immediately with IPython vs python because if pyplot is imported inside of IPython it notices and sets up the event loop integration. In the plain prompt you would get an issue eventually when the user tried to make a plot. I think moving to tk as default would be less than great. |
What do you mean exactly? Do you think it's better for Anaconda to stay with Qt5? |
Qt5 is a nicer framework and support hi-dpi screens out of the box, I think going back to Tk would be regression in user experience. |
Ok, we are just a bit worried about the notebook running in headless Docker containers. But with Matplotlib 1.5 (I think), the notebook automatically selects |
That is entirely on the jupyter side. |
If the |
That's really cool! Then I'd say this can be closed. The OP can simply set 'agg' as Matplotlib's default backend in his matplotlibrc to avoid this error. |
Re-reading this, I notice that it was originally about terminal IPython, not the kernel. What I said above about setting MPLBACKEND does not apply to terminal IPython. I'll close this now because I don't think what's reported is a bug in IPython. Maybe it's up to the user to configure a headless backend, or maybe MPL's "inside IPython" check should also check whether it's in a headless environment. Either way, I don't think there's anything IPython can do to fix it. Feel free to keep using this issue as a place to discuss it, though. |
Yes, it does seem clear that it is not an ipython bug. I would think that MPL should make the checks to allow someone to launch an ipython shell and import matplotlib.pyplot, and have that not crash, without having to change any matplotlibrc options or explicitly set the backend. |
@timothydmorton The issue is telling the difference between "The user just asked to use a GUI backend, but they only sorta-meant it and we should fall back to Agg" vs "The user just asked to use a GUI backend, we can not because there is no X-sever running so we should let them know" from a string input. The trade off has historically been in favor of the interactive users and preventing the "no plot showed up" bug and letting the "I can not use an interactive backend on a headless server" bug happen because in the later case the user gets a clear error as to what is wrong. There was some discussion recently about how to support "which ever Qt flavor is installed" as a backend and how to do backend fallbacks, but it gets a tricky in general because GUI frameworks tend to step on each other's toes if you import them simultaneously. |
I am also effected by this issue, and I cannot think of a good work around besides using regular python instead of ipython. |
@russelljjarvis it's a minor annoyance, but if the first command you run when you start up ipython is |
Yes: import matplotlib; matplotlib.use('agg') Is the first command I run, but I still get: In [1]: QXcbConnection: Could not connect to display :0
Aborted After the program has hit an error, and usually I would be left with a prompt to debug and monkey patch. I invoke python with Where the first line of file_name is I wonder if running ipcluster might be causing the problems. |
There's a solution using environment variables available here: Setting |
A colleague recently suggested the same thing. In the context of Docker your statement would be: |
I am getting the same error: Setting
|
solution in notebook directly import os
os.environ['QT_QPA_PLATFORM']='offscreen' |
As a late-ish follow up, as of Matplotlib 3.0 we now support automatic backend selection and will not try to use a GUI backend on a headless server (but will still respect an rcparams file that asks us to). |
This answer https://unix.stackexchange.com/questions/192642/wkhtmltopdf-qxcbconnection-could-not-connect-to-display |
"conda update matplotlib" fixed the problem for me. |
The following setting does work!!!export QT_QPA_PLATFORM='offscreen'
Matplotlib 3.1 cannot support automatic backend, we need to manually set 'Agg' . |
where i can change this one? |
This is my error after setting [tb571@da02 ~]$ jupyter console --kernel slicer-4.11
qt.qpa.plugin: Could not find the Qt platform plugin "offscreen" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. |
After setting
|
I am getting this error as well |
When I create a completely fresh conda envirnoment:
and then try to
import matplotlib.pyplot
from within ipython, I get the following:There is no problem when I run the same in the vanilla python shell. Happens for both py2.7.13 (ipython 5.3.0) and py3.6.1 (ipython 6.0.0).
I don't know whether this is an ipython bug or a conda bug, so I raised an issue first with anaconda, but I wanted to note it here too.
The text was updated successfully, but these errors were encountered: