[PyQt] PyQt5 and Spyder 3.3.2 Conflict, Beautiful Soup, <An error occurred while starting the kernel>

Gene Ensor g_ensor at hotmail.com
Sun Mar 24 01:28:13 GMT 2019


Team,

Per

https://github.com/spyder-ide/spyder/wiki/How-to-run-PyQt-applications-within-Spyder

I believe I have the following problem:

"The most common problem when running a PyQt multiple times inside Spyder is that a QApplication instance remains in the namespace of the IPython console kernel after the first run. In other words, when you try to re-run your application, you already have a QApplication instance initialized."

Hence when ran a second time I get "An error occurred while starting the kernel".  However I am not skilled enough to update the below code to behave correctly my environment.

Anaconda "Python 3.7.1 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10 | Spyder 3.3.2

Can you assist?  Thanks!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import sys
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5.QtCore import QUrl, QCoreApplication

import bs4 as bs
import urllib.request


class Page(QWebEnginePage):
    def __init__(self, url):
#       PyQt5 has the "minimal" platform plugin.
#       To use it, modify the argv passed to QApplication to include
#       ['-platform', 'minimal'].
        self.app = QApplication(sys.argv)
        QWebEnginePage.__init__(self)
        self.html = ''
        self.loadFinished.connect(self._on_load_finished)
        self.load(QUrl(url))
        self.app.exec_()

    def _on_load_finished(self):
        self.html = self.toHtml(self.Callable)
        print('Load finished')

    def Callable(self, html_str):
        self.html = html_str
        self.app.quit()


def main():
    page = Page('https://pythonprogramming.net/parsememcparseface/')
    soup = bs.BeautifulSoup(page.html, 'html.parser')
    js_test = soup.find('p', class_='jstest')
    print(js_test.text)    #fixed
    # output should be "Look at you shinin!"
if __name__ == '__main__': main()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190324/ed4b4039/attachment.html>


More information about the PyQt mailing list