ipython: QXcbConnection: Could not connect to display
When I create a completely fresh conda envirnoment:
conda create --name test ipython matplotlib
and then try to import matplotlib.pyplot
from within ipython, I get the following:
In [1]: import matplotlib.pyplot
In [2]: QXcbConnection: Could not connect to display
Aborted
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.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 15
- Comments: 32 (14 by maintainers)
There’s a solution using environment variables available here:
Setting
export QT_QPA_PLATFORM='offscreen'
in my.bash_profile
worked for me.@russelljjarvis it’s a minor annoyance, but if the first command you run when you start up ipython is
import matplotlib; matplotlib.use('agg')
then ipython should work for you.solution in notebook directly
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.
The following setting does work!!!
export QT_QPA_PLATFORM=‘offscreen’
Matplotlib 3.1 cannot support automatic backend, we need to manually set ‘Agg’ .
I am getting the same error:
Setting
export QT_QPA_PLATFORM='offscreen'
changed the error message to:A colleague recently suggested the same thing. In the context of Docker your statement would be:
ENV QT_QPA_PLATFORM offscreen
. I am effectively testing that now.What do you mean exactly? Do you think it’s better for Anaconda to stay with Qt5?
And if I explicitly set the backend to
'agg'
I also don’t get the error, but I’d like to avoid having to do that every time I launch ipython and want to import something that imports matplotlib.After setting
QT_QPA_PLATFORM='offscreen'
the imports of matplotlib and fastai libraries run. However, plt.figure() or any other command outputting a plot raises the following errors:This is my error after setting
export QT_QPA_PLATFORM=offscreen
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.