“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.
Re: PyQt5 and Spyder 3.3.2 Conflict, Beautiful Soup, <An error occurred while starting the kernel>
Have you verified in those cases that the app exit is being called? If you fail out because of an exception it won't be. I would really manage the app outside your class. (Does Qt really force you to inherit here?). Then you can try/finally to make sure it gets exited even after a python exception. Or even make yourself a context manager.
>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
>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 |
>Can you assist? Thanks!
>from PyQt5.QtWebEngineWidgets import QWebEnginePage
>from PyQt5.QtWidgets import QApplication, QDialog
>from PyQt5.QtCore import QUrl, QCoreApplication
>import bs4 as bs
> 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)
> self.html = ''
> def _on_load_finished(self):
> self.html = self.toHtml(self.Callable)
> print('Load finished')
> def Callable(self, html_str):
> self.html = html_str
> 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()