ejeschke / ginga

The Ginga astronomical FITS file viewer
BSD 3-Clause "New" or "Revised" License
122 stars 77 forks source link

PyQT4 and PyQT5 with Python 2 #157

Closed nabobalis closed 9 years ago

nabobalis commented 9 years ago

I had issues with Ginga not being able to load under my Arch Linux install since you can have both PyQT4 and PyQT5 with Python 2 installed at the same time.

This was the error:

Traceback (most recent call last):
  File "/usr/bin/ginga", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/home/nabobalis/GitRepos/ginga/scripts/ginga", line 14, in <module>
    main.reference_viewer(sys.argv)
  File "/home/nabobalis/GitRepos/ginga/ginga/main.py", line 489, in reference_viewer
    viewer.main(options, args)
  File "/home/nabobalis/GitRepos/ginga/ginga/main.py", line 263, in main
    from ginga.qtw.GingaQt import GingaView
  File "/home/nabobalis/GitRepos/ginga/ginga/qtw/GingaQt.py", line 17, in <module>
    from ginga.qtw.QtHelp import QtGui, QtCore, QFont, \
  File "/home/nabobalis/GitRepos/ginga/ginga/qtw/QtHelp.py", line 52, in <module>
    from PyQt4 import QtCore, QtGui
RuntimeError: the PyQt4.QtCore and PyQt5.QtCore modules both wrap the QObject class

To solve this, I uninstalled PyQT5 and it worked. Ginga was fast and everything loaded. When I did the reverse, so I uninstalled PyQT4, but had PyQT5 installed, Ginga became slower to load and off the master branch, Cuts did not work. It gave me these errors:

Traceback (most recent call last):
  File "/home/nabobalis/GitRepos/ginga/ginga/qtw/GingaQt.py", line 321, in <lambda>
    item.triggered.connect(lambda: self.start_operation_cb(title))
  File "/home/nabobalis/GitRepos/ginga/ginga/qtw/GingaQt.py", line 783, in start_operation_cb
    return self.start_local_plugin(chname, name, None)
  File "/home/nabobalis/GitRepos/ginga/ginga/Control.py", line 407, in start_local_plugin
    opmon.start_plugin_future(chinfo.name, opname, future)
  File "/home/nabobalis/GitRepos/ginga/ginga/misc/PluginManager.py", line 278, in start_plugin_future
    self.set_focus(pInfo.name)
  File "/home/nabobalis/GitRepos/ginga/ginga/misc/PluginManager.py", line 168, in set_focus
    pInfo.obj.resume()
  File "/home/nabobalis/GitRepos/ginga/ginga/misc/plugins/Cuts.py", line 389, in resume
    self.replot_all()
  File "/home/nabobalis/GitRepos/ginga/ginga/misc/plugins/Cuts.py", line 496, in replot_all
    self.plot.clear()
AttributeError: 'Cuts' object has no attribute 'plot'

and

Plugin UI failed to initialize: 'QCommonStyle' represents a C++ abstract class and cannot be instantiated
  File "/home/nabobalis/GitRepos/ginga/ginga/misc/PluginManager.py", line 228, in start_plugin_future
    pInfo.obj.build_gui(vbox)
  File "/home/nabobalis/GitRepos/ginga/ginga/misc/plugins/Cuts.py", line 151, in build_gui
    fr = Widgets.Expander("Instructions")
  File "/home/nabobalis/GitRepos/ginga/ginga/qtw/Widgets.py", line 495, in __init__
    style = QtGui.QCommonStyle()

I want to see if anyone else has these issues, or whether this is an Arch issue.

ejeschke commented 9 years ago

@nabobalis, I just have one data point for this scenario, which is an Ubuntu 14.04 box with both qt4 and qt5 installed. ginga runs fine under both and with what appears to be equally (good) speed. I only run the qt5 version with python 3 because my understanding is that qt5 is not supported under python 2.

Are you able to run matplotlib plots with the qt5agg backend under python 3? If not, you may need to install any modules necessary to get that to work as that is what will be used for plotting under ginga/qt5.

ejeschke commented 9 years ago

I should note that when I run from the same code area (with both python 2 and python 3) it sometimes seems to take a bit longer to start up after a switch, as though it is byte-compiling up a bunch of modules anew. Subsequent starts with the same version of python are fast.

ejeschke commented 9 years ago

@nabobalis, the latest commits should have taken care of the QtGui.QCommonStyle() error.

If you start the qt5 instance as:

export QT_API=pyqt
$ python3 scripts/ginga -t qt5 --loglevel=20 --stderr

do you still get the above errors?

ejeschke commented 9 years ago

@nabobalis, could you try commit 26792a5f2b7fea047c3a6b065cbc0b65aab782c4? This fixes an issue for me trying to run in the dual qt4/qt5 configuration. I believe now that I was actually running python3 with qt4 for some of the testing. I have tested with python3 and qt5 and with this commit things are working fine. I noted that at least in Ubuntu 14.04 matplotlib stable does not ship with support for qt5agg backend. I don't know the situation with Arch linux.

nabobalis commented 9 years ago

@ejeschke So I updated my local copy of ginga and used

export QT_API=pyqt
ginga -t qt5 --loglevel=20 --stderr <file>

Ginga opens and does not have that error anymore, but I get this,

Traceback (most recent call last):
  File "/home/nabobalis/GitRepos/ginga/ginga/qtw/ImageViewQt.py", line 390, in mouseMoveEvent
    self.viewer.motion_notify_event(self, event)
  File "/home/nabobalis/GitRepos/ginga/ginga/qtw/ImageViewQt.py", line 629, in motion_notify_event
    return self.make_callback('motion', button, data_x, data_y)
  File "/home/nabobalis/GitRepos/ginga/ginga/Mixins.py", line 56, in make_callback
    return super(UIMixin, self).make_callback(name, *args, **kwdargs)
  File "/home/nabobalis/GitRepos/ginga/ginga/misc/Callback.py", line 88, in make_callback
    name, str(e)))
  File "/usr/lib/python2.7/logging/__init__.py", line 1191, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/lib/python2.7/logging/__init__.py", line 1283, in _log
    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
  File "/usr/lib/python2.7/logging/__init__.py", line 1257, in makeRecord
    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
  File "/usr/lib/python2.7/logging/__init__.py", line 278, in __init__
    self.module = os.path.splitext(self.filename)[0]
  File "/usr/lib/python2.7/posixpath.py", line 98, in splitext
    return genericpath._splitext(p, sep, altsep, extsep)
  File "/usr/lib/python2.7/genericpath.py", line 109, in _splitext
    if p[filenameIndex] != extsep:
RuntimeError: maximum recursion depth exceeded in cmp

Then it core dumps.

Arch Matplotlib does ship with support for the qt5agg backend. Also, I can confirm that having both python-pyqt packages installed, ginga now does open without an issue.

If I recall, @Cadair had a different issue in a clean VM under Arch. We have a Ubuntu LTS server I plan to test on.

ejeschke commented 9 years ago

@nabobalis, I have encountered the recursion depth issue before. Ginga makes heavy use of logging and it seems that the default recursion limit of 1000 in python is not sufficient for some of the use cases in ginga.

Can you update with commit 7ea1088c46c3cd6d1e3ea3ed262adb6432fe0cf1 or later and try a couple of things and let me know the result?

1) Try running with the new --lognull option. This replaces the python logger with a NullLogger (essentially stubs that do nothing). Obviously running with no logging is not ideal, but this provides a quick way to troubleshoot whether logging is causing any problems.

2) Try running with a higher level of logging, like --loglevel=40. This should only log warnings and errors.

3) Copy the general.cfg to your $HOME/.ginga area and edit the recursion_limit setting to something like 3000. This ups the python default of 1000.

ejeschke commented 9 years ago

Glad to hear the dual qt4/qt5 setup is working.

nabobalis commented 9 years ago

The latest version now works with QT5 on my machine. No more errors and that slowness is now gone. Thanks @ejeschke!

ejeschke commented 9 years ago

Excellent news.