6

I have a problem with spyder.

I just installed on this laptop Python 3.7 and Spyder, as I did on many others. However this time, it doesn't work.

I installed Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32 with the installer. I changed the path to a custom path: C:\Python\Python37, I added the precompile library and I added the path to the environment. The laptop was rebooted at that point.

Then I updated pip:

py -3.7 -m pip install --upgrade pip

And then I installed spyder:

py -3.7 -m pip install spyder

I then try to launch spyder with the file:

C:\Python\Pythno37\Lib\site-packages\spyder\app\start.py

I get the error:

ModuleNotFoundError: No module named 'PyQt5.QtWebKitWidgets'

PyQt5 is installed with version 5.12.

No clue why it doesn't work...

EDIT: The full error message:

Error msg

It sugggest that the problem comes from qtpy. However, the corresponding file imports:

from . import PYQT5,PYSIDE2, PYQT4, PYSIDE, PythonQtError


# To test if we are using WebEngine or WebKit
WEBENGINE = True


if PYQT5:
    try:
        from PyQt5.QtWebEngineWidgets import QWebEnginePage
        from PyQt5.QtWebEngineWidgets import QWebEngineView
        from PyQt5.QtWebEngineWidgets import QWebEngineSettings
    except ImportError:
        from PyQt5.QtWebKitWidgets import QWebPage as QWebEnginePage
        from PyQt5.QtWebKitWidgets import QWebView as QWebEngineView
        from PyQt5.QtWebKit import QWebSettings as QWebEngineSettings
        WEBENGINE = False

The PyQt5.QtWebEngnieWidgets is correctly used.

Mathieu
  • 5,410
  • 6
  • 28
  • 55
  • Possible duplicate of [Cannot import QtWebKitWidgets in PyQt5](https://stackoverflow.com/questions/37876987/cannot-import-qtwebkitwidgets-in-pyqt5) – razimbres Feb 25 '19 at 15:22
  • @Rubens_Z Not really because it is not my code but the official spyder release... which should work perfectly fine. Moreover, this import is deprecated since several months (years?), thus the change in the spyder code should have occur. Finally, I installed python and spyder in the same way 2 weeks ago on another laptop. – Mathieu Feb 25 '19 at 15:27
  • I also had a problem with PyQt5 in latest Spyder running on Ubuntu. Spyder didn't start due to segmentation fault (core dumped). In that specific case, I updated PyQt5 and setuptools. – razimbres Feb 25 '19 at 15:32
  • @Rubens_Z I'm running on Windows. I updated PyQt5 using: `py -3.7 -m pip install --upgrade pyqt5`. It is now up to date on version 5.12. I'll try to update `setuptools`. – Mathieu Feb 25 '19 at 15:33
  • The problem has been addressed https://github.com/spyder-ide/spyder/issues/8747. – Mathieu Feb 26 '19 at 08:34

2 Answers2

14

I swapped Pyqt5 version from 5.12 to 5.11.2 with:

py -m pip install pyqt5==5.11.2

And now it works...

Mathieu
  • 5,410
  • 6
  • 28
  • 55
  • Amazin man, absolutely amazing. I did pip install pyqt5==5.11.2 and it updated from 5.9.2 to this version and Spyder ran successfully. Thanks – Anuvrat Tiku Apr 07 '19 at 21:03
9

Three days ago I was playing around with Python, Mayavi and Jupyter Notebooks to create visualizations. This required to install PyQt5.

Due to constantly reaching memory errors, I've decided to test without using virtualenv's and installed the needed requirements on my local environment (which of course didn't solve).

After that, I was on my way to create visualizations using matplotlib and other Python libraries but can't launch Spyder from the Anaconda Navigator.

This is the error showing up, which is similar to yours

Traceback (most recent call last):
File "C:\Users\tiago\Anaconda3\lib\site-packages\qtpy\QtWebEngineWidgets.py", line 22, in 
from PyQt5.QtWebEngineWidgets import QWebEnginePage
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\tiago\Anaconda3\Scripts\spyder-script.py", line 10, in 
sys.exit(main())
File "C:\Users\tiago\Anaconda3\lib\site-packages\spyder\app\start.py", line 186, in main
from spyder.app import mainwindow
File "C:\Users\tiago\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 90, in 
from qtpy import QtWebEngineWidgets # analysis:ignore
File "C:\Users\tiago\Anaconda3\lib\site-packages\qtpy\QtWebEngineWidgets.py", line 26, in 
from PyQt5.QtWebKitWidgets import QWebPage as QWebEnginePage
ModuleNotFoundError: No module named 'PyQt5.QtWebKitWidgets'

The correct answer didn't work in my case.

This problem had to do with the PyQt5 installation. The way to fix it was to uninstall it

pip uninstall PyQt5

Solved after uninstalling PyQt5

and then Spyder launched perfectly

Spyder finally launched

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
  • 2
    So when I had this problem, I was not using anaconda. I was installing spyder by pip. What I noticed, is that the latest version of spyder was not compatible (yet) with the latest version of pyqt5 in which the module `QtWebKitWidgets` was changed of place/renamed. I forgot which one it is, but at the time, the problem was addressed on git. I don't know if it was resolved with the latest version of spyder. In your case, the previous installation of pyqt5 might have been the cause, thus the uninstall/reinstall worked out. Thanks for adding this answer for future user running into this issue. – Mathieu Oct 12 '19 at 15:31
  • 1
    @Mathieu i was pressured into sharing here instead, https://stackoverflow.com/q/58338194/5675325 – Tiago Martins Peres Oct 12 '19 at 15:33
  • 2
    What is surprising is that spyder is using pyqt5. Pyqt5 is a required package for spyder. I guess in your guess it had to do with the use of anaconda. Maybe the spyder in anaconda is a bit different and/or is using a specific install of pyqt5. – Mathieu Oct 12 '19 at 17:17
  • 1
    You're right, that's what ccordoba12 (Spyder maintainer) says here: https://github.com/spyder-ide/spyder/issues/8952 – Tiago Martins Peres Oct 12 '19 at 18:45