Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Try importing PySide, if we can't find sip. #2142

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

Merged
merged 2 commits into from
Jul 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/faq/usage_faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,20 @@ macosx Cocoa rendering in OSX windows
.. _TkInter: http://wiki.python.org/moin/TkInter
.. _PyQt4: http://www.riverbankcomputing.co.uk/software/pyqt/intro

How do I select PyQt4 or PySide?
========================================

You can choose either PyQt4 or PySide when using the `qt4` backend by setting
the appropriate value for `backend.qt4` in your :file:`matplotlibrc` file. The
default value is `PyQt4`.

The setting in your :file:`matplotlibrc` file can be overridden by setting the
`QT_API` environment variable to either `pyqt` or `pyside` to use `PyQt4` or
`PySide`, respectively.

Since the default value for the bindings to be used is `PyQt4`,
:mod:`matplotlib` first tries to import it, if the import fails, it tries to
import `PySide`.

.. _interactive-mode:

Expand Down
14 changes: 12 additions & 2 deletions lib/matplotlib/backends/qt4_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@
# of file dialog.
_getSaveFileName = None

# Flag to check if sip could be imported
_sip_imported = False

# Now perform the imports.
if QT_API in (QT_API_PYQT, QT_API_PYQTv2):
import sip
try:
import sip
_sip_imported = True
except ImportError:
# Try using PySide
QT_API = QT_API_PYSIDE

if _sip_imported:
if QT_API == QT_API_PYQTv2:
if QT_API_ENV == 'pyqt':
cond = ("Found 'QT_API=pyqt' environment variable. "
Expand Down Expand Up @@ -76,7 +86,7 @@
# call to getapi() can fail in older versions of sip
_getSaveFileName = QtGui.QFileDialog.getSaveFileName

else: # can only be pyside
else: # try importing pyside
from PySide import QtCore, QtGui, __version__, __version_info__
if __version_info__ < (1, 0, 3):
raise ImportError(
Expand Down