Bug report #18258

executing Python command ("from PyQt4.QtCore import *") crashes QGIS

Added by Erik Sigra over 6 years ago. Updated about 6 years ago.

Status:Closed
Priority:High
Assignee:Denis Rouzaud
Category:Python bindings / sipify
Affected QGIS version:3.0.0 Regression?:No
Operating System:Gentoo Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:Yes Copied to github as #:26149

Description

Executing the Python command "from PyQt4.QtCore import *" crashes QGIS 3.0.0. Hope that this will be easy enough to reproduce. Otherwise I am willing to rebuild the relevant packages with debug symbols and attach a backtrace.

I as a user assume that a Python command that I enter is considered to be input to QGIS. (A program should of course not crash on any input.) But maybe the QGIS project officially considers the user's act of giving a Python command not as giving an input to QGIS but modifying QGIS itself (equivalent to flipping a bit in the executable file /usr/bin/qgis). If so, this may not be a bug in QGIS as delivered, but rather in the the user's own modified program produced by executing that command in QGIS, which might then not belong in this issue tracker.

History

#1 Updated by Nyall Dawson over 6 years ago

  • Status changed from Open to Feedback

You should be using

from qgis.PyQt.QtCore import *

Qgis 3 uses pyqt5, so I'd expect issues if you try to import pyqt4

#2 Updated by Giovanni Manghi over 6 years ago

  • Regression? changed from Yes to No
  • Priority changed from Normal to High

#3 Updated by Erik Sigra over 6 years ago

I do not know what the cleanest fix is. Someone familiar with the code might know. Maybe it can be fixed deep in there somewhere. Maybe that is difficult and the best thing to do (at least for the short term) is to blacklist modules that are known to be incompatible (in this case PyQt4), filter out commands that attempt to import them and give a warning (maybe with a hint what to use instead).

What I do know is that users will try to open existing projects and run the scripts in them. (Or script snippets from tutorials or other sources.) They will notice that QGIS suddenly disappears and draw the conclusion that QGIS 3 is unstable and not ready (yet). Many will not bother to test their script line by line to see what exactly makes QGIS crash. Some will not even realize that it is caused by a script.

#4 Updated by Giovanni Manghi over 6 years ago

Erik Sigra wrote:

I do not know what the cleanest fix is. Someone familiar with the code might know. Maybe it can be fixed deep in there somewhere. Maybe that is difficult and the best thing to do (at least for the short term) is to blacklist modules that are known to be incompatible (in this case PyQt4), filter out commands that attempt to import them and give a warning (maybe with a hint what to use instead).

What I do know is that users will try to open existing projects and run the scripts in them. (Or script snippets from tutorials or other sources.) They will notice that QGIS suddenly disappears and draw the conclusion that QGIS 3 is unstable and not ready (yet). Many will not bother to test their script line by line to see what exactly makes QGIS crash. Some will not even realize that it is caused by a script.

or maybe users should be aware that any major release of a software brings important changes?

#5 Updated by Erik Sigra over 6 years ago

I just had a look at how a plain Python session handles the import of PyQt4 when PyQt5 is already in use. It does not die on signal 11, like QGIS 3 does, but gives an informative error message:
RuntimeError: the PyQt4.QtCore and PyQt5.QtCore modules both wrap the QObject class

#6 Updated by Giovanni Manghi about 6 years ago

  • Resolution set to invalid
  • Status changed from Feedback to Closed

Also available in: Atom PDF