Qt integration and sip API

Dear list,

I'm trying to to use matplotlib in a Qt application which needs the
sip API set to 2

  import sip
  sip.setapi('QString', 2)

However if I do this I get this error

  ImportError: cannot import name QString

I'm wondering if I'm the first to stumble upon this one, or this is a
known solution.

Below the whole Traceback.

Thanks,
Michele.

  In [3]: import sip

  In [4]: sip.setapi('QString', 2)

  In [5]: import matplotlib.pyplot as plt

···

---------------------------------------------------------------------------
  ImportError Traceback (most recent call last)

  /home/mattions/Work/model/MSN/Neuronvisio/examples/<ipython console>
in <module>()

  /usr/lib/pymodules/python2.6/matplotlib/pyplot.py in <module>()
     93
     94 from matplotlib.backends import pylab_setup
  ---> 95 new_figure_manager, draw_if_interactive, show = pylab_setup()
     96
     97 @docstring.copy_dedent(Artist.findobj)

  /usr/lib/pymodules/python2.6/matplotlib/backends/__init__.pyc in pylab_setup()
     23 backend_name = 'matplotlib.backends.%s'%backend_name.lower()
     24 backend_mod = __import__(backend_name,
  ---> 25 globals(),locals(),[backend_name])
     26
     27 # Things we pull in from all backends

  /usr/lib/pymodules/python2.6/matplotlib/backends/backend_qt4agg.py in
<module>()
     10
     11 from backend_agg import FigureCanvasAgg
  ---> 12 from backend_qt4 import QtCore, QtGui, FigureManagerQT,
FigureCanvasQT,\
     13 show, draw_if_interactive, backend_version, \
     14 NavigationToolbar2QT

  /usr/lib/pymodules/python2.6/matplotlib/backends/backend_qt4.py in <module>()
     14 from matplotlib.mathtext import MathTextParser
     15 from matplotlib.widgets import SubplotTool
  ---> 16 import matplotlib.backends.qt4_editor.figureoptions as figureoptions
     17
     18 try:

  /usr/lib/pymodules/python2.6/matplotlib/backends/qt4_editor/figureoptions.py
in <module>()
      9 import os.path as osp
     10
  ---> 11 import matplotlib.backends.qt4_editor.formlayout as formlayout
     12 from PyQt4.QtGui import QIcon
     13

  /usr/lib/pymodules/python2.6/matplotlib/backends/qt4_editor/formlayout.py
in <module>()
     57 QDateEdit, QDateTimeEdit, QFont, QFontComboBox,
     58 QFontDatabase, QGridLayout)
  ---> 59 from PyQt4.QtCore import (Qt, SIGNAL, SLOT, QSize, QString,
     60 pyqtSignature, pyqtProperty)
     61 from datetime import date

  ImportError: cannot import name QString

Following up, after a bit of research...

It seems it's alla about QString (which is gone in api 2)
it is suggested to convert the QString into a unicode python2 string
http://wiki.python.org/moin/PortingPythonToPy3k/PyQt4

Do you think could be the way to go for the qt backend?

Cheers,
Michele.

···

On Fri, Feb 25, 2011 at 12:30 AM, Michele Mattioni <mattions@...287...> wrote:

Dear list,

I'm trying to to use matplotlib in a Qt application which needs the
sip API set to 2

   import sip
   sip\.setapi\(&#39;QString&#39;, 2\)

However if I do this I get this error

   ImportError: cannot import name QString

I'm wondering if I'm the first to stumble upon this one, or this is a
known solution.

Below the whole Traceback.

Thanks,
Michele.

   In \[3\]: import sip

   In \[4\]: sip\.setapi\(&#39;QString&#39;, 2\)

   In \[5\]: import matplotlib\.pyplot as plt
   \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
   ImportError                               Traceback \(most recent call last\)

   /home/mattions/Work/model/MSN/Neuronvisio/examples/&lt;ipython console&gt;

in <module>()

   /usr/lib/pymodules/python2\.6/matplotlib/pyplot\.py in &lt;module&gt;\(\)
            93
            94 from matplotlib\.backends import pylab\_setup
   \-\-\-&gt; 95 new\_figure\_manager, draw\_if\_interactive, show = pylab\_setup\(\)
            96
            97 @docstring\.copy\_dedent\(Artist\.findobj\)

   /usr/lib/pymodules/python2\.6/matplotlib/backends/\_\_init\_\_\.pyc in pylab\_setup\(\)
            23         backend\_name = &#39;matplotlib\.backends\.%s&#39;%backend\_name\.lower\(\)
            24     backend\_mod = \_\_import\_\_\(backend\_name,
   \-\-\-&gt; 25                              globals\(\),locals\(\),\[backend\_name\]\)
            26
            27     \# Things we pull in from all backends

   /usr/lib/pymodules/python2\.6/matplotlib/backends/backend\_qt4agg\.py in

<module>()
10
11 from backend_agg import FigureCanvasAgg
---> 12 from backend_qt4 import QtCore, QtGui, FigureManagerQT,
FigureCanvasQT,\
13 show, draw_if_interactive, backend_version, \
14 NavigationToolbar2QT

   /usr/lib/pymodules/python2\.6/matplotlib/backends/backend\_qt4\.py in &lt;module&gt;\(\)
            14 from matplotlib\.mathtext import MathTextParser
            15 from matplotlib\.widgets import SubplotTool
   \-\-\-&gt; 16 import matplotlib\.backends\.qt4\_editor\.figureoptions as figureoptions
            17
            18 try:

   /usr/lib/pymodules/python2\.6/matplotlib/backends/qt4\_editor/figureoptions\.py

in <module>()
9 import os.path as osp
10
---> 11 import matplotlib.backends.qt4_editor.formlayout as formlayout
12 from PyQt4.QtGui import QIcon
13

   /usr/lib/pymodules/python2\.6/matplotlib/backends/qt4\_editor/formlayout\.py

in <module>()
57 QDateEdit, QDateTimeEdit, QFont, QFontComboBox,
58 QFontDatabase, QGridLayout)
---> 59 from PyQt4.QtCore import (Qt, SIGNAL, SLOT, QSize, QString,
60 pyqtSignature, pyqtProperty)
61 from datetime import date

   ImportError: cannot import name QString