Python 2.7.11 - ImportError: cannot import name QtWebKit - Kali Linux / Debian 8

倖福魔咒の 提交于 2021-02-08 06:17:15

问题


I'm trying to launch an app dependant on QtWebKit but i'm unable to import the module. I've tried debugging by launching python and importing other modules. They all work fine (e.g. from PyQt4 import QtGui, QtCore) works without any issues, but when i run

from PyQt4 import QtGui, QtCore, QtWebKit

I receive the following:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name QtWebKit

I have also tried the following to no avail (they install fine but do not fix the issue):

apt-get install --reinstall python-qt4
apt-get install --reinstall python-2.7

回答1:


This is an issue with the app, sparta?. Debian Stretch which Kali Rolling is based on has mothballed QtWebKit in PyQt4.

The latest version does not contain QtWebkit.so.

Unfortunately the code in question needs to be updated to use an alternative such as PyQt5 equivalent module.

A bug report concerning this can be found on the kali bug report site from Jun/2/2016


optional bodge/quick n dirty fix [works in latest build of Kali]

In the mean time and if it is sparta and you need it functional now:
apt-get install python-pyside.qtwebkit
clone a copy from https://github.com/SECFORCE/sparta to where ever suits, in my case /opt/recon/sparta, this preserves the system version so it can fixed updated normally.
edit sparta.py

remove QtWebKit from line 22
insert the code from line 26 to 30

21 try: 
22    from PyQt4 import QtGui, QtCore
23 except:
24    print "[-] Import failed. PyQt4 library not found. \nTry installing it with: apt-get install python-qt4"
25    exit()
26 try:
27    from PySide import QtWebKit
28 except:
29    print "[-] Import failed. QtWebkit library not found. \nTry installing it with: apt-get install python-pyside.qtwebkit"
30    exit()

edit ui/view.py
comment out line 15

15 #from PyQt4 import QtWebKit                                              # to show html code (help menu)
16 from PySide import QtWebKit                                              # to show html code (help menu)

edit line 54 the original can be seen below

54 self.helpWidget.load(QUrl('./doc/help.html'))

This should be modified to

54 self.helpWidget.load('./doc/help.html')  

Disclaimer This is a 5 minute fix, look to the project homepage for longterm fix.




回答2:


On latest version sparta and Kali:

Linux kali 4.14.0-kali1-amd64 #1 SMP Debian 4.14.2-1kali1 (2017-12-04) x86_64 GNU/Linux

You need modify:

Comment :

16 #from PyQt4 import QtWebKit

Add:

17 from PySide import QtWebKit

Modify:

54 self.helpWidget.load('./doc/help.html')




回答3:


Unfortunately developers have no time and resources to fix the issue permanently. But you can get updated and compatible with Kali version here https://github.com/alexxn/sparta




回答4:


install python3-pyqt5.qtwebkit

the solution is here: https://github.com/sourcepole/qgis-openlayers-plugin/issues/56#issuecomment-387223048

worked for me



来源:https://stackoverflow.com/questions/37604532/python-2-7-11-importerror-cannot-import-name-qtwebkit-kali-linux-debian-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!