Question

I'm having an odd module import issue when trying to work with PyQt4. I'm able to run the following imports, independent of each other, without getting errors:

import PyQt4
from PyQt4 import *
from PyQt4 import QtWebKit
from PyQt4.QtWebkit import *

I start getting errors when I try to import specific modules in PyQt4.QtWebKit though, but it doesn't happen to all of the modules. Here's an example:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/webscraping/webkit.py", line 16, in <module>
from PyQt4.QtWebKit import QWebFrame, QWebView, QWebElement, QWebPage, QWebSettings
ImportError: cannot import name QWebElement

Every module in that error works except QWebElement. Notice that the error says that it can't import the module, not that the module doesn't exist. I've tried reinstalling the packages but haven't had much luck.

Here are my system specs and packages I installed:

  • CentOS Linux 2.6.32-431.5.1.el6.x86_64 GNU/Linux
  • Python 2.6.6

Installed:

  • sip.x86_64 (Version : 4.9.3, Release : 1.el6)
  • qt.x86_64 (Version : 4.6.2, Release : 28.el6_5)
  • PyQt4.x86_64 (Version : 4.6.2, Release : 9.el6)
  • PyQt4-devel.x86_64 (Version : 4.6.2, Release : 9.el6)
  • PyQt4-webkit.x86_64 (Version : 4.6.2, Release : 8.el6)
  • PyQt4-webkit-devel.x86_64 (Version : 4.6.2, Release : 8.el6)
  • webscraping (Version: 1.4)
Was it helpful?

Solution

The PyQt versions don't necessarily stay in sync with the Qt versions anymore. PyQt-4.7 is the first version that fully supports Qt-4.6.

I still have an old build of PyQt-4.7, and I can confirm that the import statement in the question does not produce errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top