Khris Khris - 10 months ago 90
Python Question

PyDev Seaborn in Eclipse: "QPixmap: It is not safe to use pixmaps outside the GUI thread" on PyDev autocompletion popup

I'm getting the error

QPixmap: It is not safe to use pixmaps outside the GUI thread

when manually entering the following statements in Seaborn in the
-shell using PyDev in Eclipse:

import matplotlib.pyplot as mpl
import seaborn as sns
import pandas as pd
import numpy as np

# Turn interactive mode off:

# Create some example Data:
df = pd.DataFrame({'A':np.random.rand(20),'B':np.random.rand(20)})

# Create seaborn PairGrid instance:
pg = sns.PairGrid(df)

At this point when I continue the last statement with a dot to e.g. chain a
-method, like this:

pg = sns.PairGrid(df).

then Eclipse is trying to show a popup of all possible completions but that popup is immediatly getting closed and the console is getting filled with the aforementioned error, 42 lines of it to be precise.

I can continue and do this without problem:

gp = sns.PairGrid(df).map(mpl.scatter)

And I get my plot just fine.

The same happens when doing

While playing around earlier I also got into situations where the console was actually killed by this error, I just can't replicate the steps that lead to this anymore.

Researching on this site it looked like it has to do with threading which I'm not using at all. Does Seaborn use it?

I want to create my plots by first creating a Grid/Figure and doing the plotting later, but this error suggests that this isn't a safe way to do things though the Seaborn doc says it's fine to do it like that:


When doing the same thing in Spyder I'm not getting the error but this warning when doing

C:\Anaconda2\lib\site-packages\matplotlib\ UserWarning:
matplotlib is currently using a non-GUI backend, so cannot show the figure
"matplotlib is currently using a non-GUI backend, "

When interactive mode is off I'm not seeing any graphic. With interactive mode on I'm still seeing the warning but get the graphic inline.

No popup in either case though. In Eclipse I'm getting both the error and the popup.


Running the whole thing as a script in Eclipse does not produce any error, only the manual entering like described above does.

Answer Source

I took a look at and the issue is that the code-completion on PyDev is being triggered in a secondary thread, not in the main (UI) thread.

I.e.: the code completion in the interactive console is not expecting that it'll touch code that'll actually interact with the gui.

For this to work, the completion command has to be queued for the main thread (as the regular commands are queued) and the thread has to wait for it to finish to then return its value.

Please report this as an issue in the PyDev tracker: (i.e.: code-completion in the interactive console should happen in the UI thread).