ContinuumIO / anaconda-issues

Anaconda issue tracking
648 stars 223 forks source link

Updating matplotlib to 2.0.0 causing problems when plotting: error/warning message "failed to get the current screen resources" #1440

Closed jdhao closed 7 years ago

jdhao commented 7 years ago

I am using CentOS 7 and Anaconda 2. I connect to the CentOS 7 server using putty and Xming.

I updated the matplotlib package to the latest version (2.0.0) recently and found a lot of annoying problems. Following the instrcutions at https://github.com/ContinuumIO/anaconda-issues/issues/1249, I was able to fix the problem.

This application failed to start because it could not find or load the Qt platform plugin "xcb" in "". Available platform plugins are: minimal, offscreen, xcb. Reinstalling the application may fix this problem. Aborted

But there is another annoying problem, every time I execute a python script in the shell using python simple.py, an error/warning message occured:

failed to get the current screen resources QXcbConnection: XCB error: 170 (Unknown), sequence: 164, resource id: 90, major code: 146 (Unknown), minor code: 20

The simple.py script could be

import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [2, 4, 6]
plt.plot(x, y)
plt.show()

If I comment out plt.show or replace it with plt.savefig('simple.py') the error message becomes solely

failed to get the current screen resources

I have search the web, but found no helpful message about how to solve this issue. I am not familiar with the qt and xcb package, I guess this still has something to do with the qt package and xcb.
Please let me know if you need further information.

ccordoba12 commented 7 years ago

@mingwandroid?

mingwandroid commented 7 years ago

No idea! It doesn't sound like this is worse than just annoying though, right?

jdhao commented 7 years ago

I also open this issue in the matplotlib repo, https://github.com/matplotlib/matplotlib/issues/8058. The suggestion given is that this is due to the problem with qt5.x. I managed to install matplotlib 2.0.0 with qt 4.x, then there is no annoying error message.

mingwandroid commented 7 years ago

So to confirm it is only an annoyance? The warning isn't causing anything to function incorrectly? I need to know this for prioritization reasons. If you are avoiding Qt5 because you do not like to see a warning printed out that sounds like your preference..

ccordoba12 commented 7 years ago

@tacaswell, what does Continuum need to do to better support Matplotlib with Qt5? Are there missing things we can fix/improve to make these two packages work as expected?

jdhao commented 7 years ago

@mingwandroid, the script execute correctly and generate the desired plot despite this annoying message when using qt 5.x. But I am not sure if internal error occurs.

tacaswell commented 7 years ago

@ccordoba12 I think something got lost in translation.

The issue here is that when the OP went from qt4 -> qt5 they started to get extra warnings when using qt5 over ssh from a windows box to a linux server. There are bunch of moving pieces in there, any of which could be miss configured / built. Matplotlib binds to qt via pyqt / pyside at runtime. The OP also reported that they get the same error using pyqt directly ( https://github.com/matplotlib/matplotlib/issues/8058#issuecomment-278894598 ) which makes in very unlikely there is anything Matplotlib specific about his issue.

The main issue here is that the OP wants to use 2.0 + qt4 which at this point requires going to conda-forge.

What I think continuum should be better about is providing a way to pick qt4 or qt5 and have Matplotlib work (right now the build process edits the default rcparam to pick one of them and it gets pinned in the requirements). Probably just by having even/odd builds with are identical other than the patch + qt pinning? I have lost track of where the split-package building is, an other solution there is to split the rcparams package from the main code package if that is ready.

qt4 -> qt5 is a small version of py2 -> py3 :smiling_imp: not everyone is ready to move over yet.

mingwandroid commented 7 years ago

@tacaswell, other than this issue, which is AFAICT (though I'm still awaiting feedback) only an annoyance at some warning text being printed, can you point to something widely used that is still on Qt4?

tacaswell commented 7 years ago

In my experience GUI code tends to be very 'write-once-read-never'. I suspect many people (including my day-job) have little things that import PyQt4 explicitly (without going through a shim/compatibility layer) that will need some work to move to pyqt5.

mingwandroid commented 7 years ago

What I think continuum should be better about is providing a way to pick qt4 or qt5 and have Matplotlib work

A lot of effort was spent trying to make qt4 and qt5 co-exist and it had to be abandoned.

jdhao commented 7 years ago

@mingwandroid Now the new Anaconda distribution is packaged with matplotlib 2.0.0 and qt 5.6.* . The same warning message still occurs. I wonder if there are plans to fix this issue.

ccordoba12 commented 7 years ago

No, there aren't, because this is a harmless warning.

NoushNabi commented 6 years ago

I had the same problem. You can add these 2 lines at beginning of your code:

import matplotlib matplotlib.use("TkAgg")

It worked for me.

robertlugg commented 6 years ago

If this is the same problem I'm seeing, it is fatal as it results in an Abort. The simple.py code from @jdhao cannot be caught:

import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [2, 4, 6]
plt.plot(x, y)
try:
    plt.show()
except:
    print("caught!")
print("continuing")

as shown in the following session:

168> python
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> x = [1, 2, 3]
>>> y = [2, 4, 6]
>>> plt.plot(x, y)
This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".

Reinstalling the application may fix this problem.
Abort
169> (shell errors as the rest of my pasting comes in)

The code provided by @NoushNabi, when placed before the other lines allows me to actually see the plot without problem.

NOTE: Even with the same install, some machines work without problem, others require the .use() call.

I believe the problem is related to the "backend" of matplotlib as referenced: https://stackoverflow.com/a/41210664/2184122 and https://matplotlib.org/faq/usage_faq.html#what-is-a-backend

I'm sorry, I can't suggest how it might be fixed.