Skip to content
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

Unable to use PySide with gui=qt #6164

Closed
JCorson opened this issue Mar 16, 2016 · 18 comments
Closed

Unable to use PySide with gui=qt #6164

JCorson opened this issue Mar 16, 2016 · 18 comments
Labels
Milestone

Comments

@JCorson
Copy link

JCorson commented Mar 16, 2016

Using matplotlib 1.5.1 with Enthought Canopy (python 2.7.10 and ipython 4.1.2), if I run ipython --gui=qt and then import matplotlib.pyplot as plt the following exception is raised despite both PySide and PyQt4 being installed.

ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5,
or PySide package to be installed, but it was not found.

This happens with matplotlibrc backend.qt4 : PySide but not backend.qt4 : PyQt4.

@JCorson
Copy link
Author

JCorson commented Mar 16, 2016

I have also reproduced this issue in anaconda with python 2.7.11 and ipython 4.0.1.

@tacaswell tacaswell added this to the 1.5.2 (Critical bug fix release) milestone Mar 16, 2016
@tacaswell
Copy link
Member

What does

from PySide import QtCore, QtGui, __version__, __version_info_

do?

@tacaswell
Copy link
Member

I can not reproduce this on 2.7 or 3.5 with pyside installed from Arch system packages in a venv + pip installed mpl 1.5.1.

@JCorson
Copy link
Author

JCorson commented Mar 16, 2016

@tacaswell Thank you for the pointer. I think I have the issue narrowed down. If I have both PyQt4 and PySide installed and do not have QT_API set in my environment, ipython --gui=qt seems to default to PyQt. In matplotlibrc I have backend.qt4 set to PySide and that import fails because PyQt is already imported. Your suggested import statement succeeds when PyQt is not installed, but fails with the following when PyQT is installed.

ImportError:
    Importing PySide disabled by IPython, which has
    already imported an Incompatible QT Binding: pyqtv1

Is it possible for matplotlib to check and see if an existing qt binding is already imported and use that instead of backend.qt4?

Our basic use-case is that we want users to run a file that creates a matplotlib animation and specify qt as the backend. ipython --gui=qt <filename> works with the above caveats. ipython --matplotlib=qt <filename> would be ideal, but the figure containing the animation does not persist.

@tacaswell
Copy link
Member

All of that logic lives in backends/qt_compat.py which now shims across pyqt4, pyqt5, pyside, pyside2, + some API version settings.

Before doing any rcparams look up we could check what is already in sys.modules.

IPython has their own qt shim layer which might be part of what is causing the mis-match.

@JCorson
Copy link
Author

JCorson commented Mar 17, 2016

Before doing any rcparams look up we could check what is already in sys.modules.

That sounds like a good solution to me.

@tacaswell
Copy link
Member

Can you check if #6174 work for you?

@JCorson
Copy link
Author

JCorson commented Mar 18, 2016

Sure does @tacaswell. Just tested it out and works great. Thanks for the fix.

tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 22, 2016
If PySide, PyQt4, or PyQt5 are imported do not consult rcparams or
ENV variable to decide which backend to use.

This is a case where ignoring user input is sensible because the Qt
bindings are mutually exclusive and attempting to import a second
binding will fail.  This can result in stand-alone scripts / mpl
embeddings which are dependent on the rcparams to function correctly.

Importing a specific Qt binding is stronger signal of user intent that
either of the other two configuration options and should take
precedence.

closes matplotlib#6164
@bhlevca
Copy link

bhlevca commented Sep 23, 2016

I think this issue has to be fixed in matplotlib. I got he same error, but strangely enough it shows only when in debug mode (using pycharm).

I got it "fixed" by uninstalling all the pyside packages.

from PySide import QtCore, QtGui, version, version_info

has never worked for me. I always get an error ImportError: cannot import name 'version' whether I have PySide installed or not.

Uninstalling PySide solved the problem for me, but the handing of the problem is not properly done and its message is misleading. The checks should say something about the incompatibility between the PyQt and PySide. Why is this showing only in debug mode? Is there anything configured wrong on my system?

@tacaswell
Copy link
Member

@bhlevca What version of mpl are you using? This fix should be in 1.5.3 and the 2.0.0 betas.

@bhlevca
Copy link

bhlevca commented Sep 24, 2016

I have 1.5.3 for python 3 and 1.5.1 for python 2, but I use only python 3 and the error I reported was in an python 3 environment.

Do you want me do do any tests to get to the problem quickly?

@tacaswell
Copy link
Member

@bhlevca Please open a new issue with exactly what you are doing.

@bhlevca
Copy link

bhlevca commented Sep 24, 2016

I am debugging something at the moment and in order to reproduce the issue I will have the reinstall PySide. If I have time tonight I will try to reinstall PySide and reproduce the issue again or I can jsut copy my initial report and open the issue with that. Basically when in debugging mode with pyside installed the debugging session is immediately stopped in qt_compat.py at this line where it rises an exception:

if QT_API == QT_API_PYSIDE:  # try importing pyside
    try:
        from PySide import QtCore, QtGui, __version__, __version_info__               <== this fails
    except ImportError:
        raise ImportError(
            "Matplotlib qt-based backends require an external PyQt4, PyQt5,\n" <== this is printed on screen
            "or PySide package to be installed, but it was not found.")

@tacaswell
Copy link
Member

What version of pyside do you have installed?

14:54 $ python
Python 3.5.2 (default, Jun 28 2016, 08:46:01) 
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PySide import QtCore, QtGui, __version__, __version_info__
>>> __version__
'1.2.4'
>>> __version_info__
(1, 2, 4, 'final', 0)
>>> 

@tacaswell
Copy link
Member

https://srinikom.github.io/pyside-docs/pysideversion.html

As of 1.0.2 this is the documented way to get the version of pyside.

@bhlevca
Copy link

bhlevca commented Sep 24, 2016

I don't have PySide anymore as it did not work for me with it installed as I explained above. As for Python version I have 3.4.5

:~> python3
Python 3.4.5 (default, Jul 03 2016, 13:32:18) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PySide import QtCore, QtGui, __version__, __version_info__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'PySide'
>>> 



@tacaswell
Copy link
Member

That trace back makes me think you do not have pyside installed properly.

@bhlevca
Copy link

bhlevca commented Sep 24, 2016

As I said I removed it because it was causing problems. Therefore, I don't have pyside installed at all on my system. NO PySide. so the trace is normal. I will install it back what and if I get some free time to play with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants