html2.WebView fails on 4.2.1 [due to incomplete build]

While testing one of my applications with wxPython 4.2.1, I noticed that html2.WebView was failing. It previously worked fine using 4.2.0.

I checked version 4.2.1 of the wxPython demo and the HTML2_WebView example also fails.

I also checked the webview_sample.py script in the demo’s samples/html2/ directory and it too fails, with the same error that I get in my application. Here is the traceback:

richardt@Pavilion:~/.../wxPython-demo-4.2.1/samples/html2 $ python3 webview_sample.py 
Traceback (most recent call last):
  File "/home/richardt/Development/python/tools/wxpython/wxPython-demo-4.2.1/samples/html2/webview_sample.py", line 263, in <module>
    main()
  File "/home/richardt/Development/python/tools/wxpython/wxPython-demo-4.2.1/samples/html2/webview_sample.py", line 255, in main
    frm = SampleFrame(None)
  File "/home/richardt/Development/python/tools/wxpython/wxPython-demo-4.2.1/samples/html2/webview_sample.py", line 34, in __init__
    pnl = WebViewPanel(self, url)
  File "/home/richardt/Development/python/tools/wxpython/wxPython-demo-4.2.1/samples/html2/webview_sample.py", line 58, in __init__
    self.wv = webview.WebView.New(self)
NotImplementedError

[All testing done using Python 3.10.6 + wxPython 4.2.1 gtk3 (phoenix) wxWidgets 3.2.2.1 on Linux Mint 21.1].

Is there a different technique needed to use WebView in version 4.2.1 ?

How did you install 4.2.1? Did you build it yourself or did you use one of the wheels from extras.wxpython.org?

I used the following alias:

alias pip-upgrade-all='pip freeze --user | cut -d'\''='\'' -f1 | xargs -n1 pip install -U'

When it got to wxPython, as far as I can tell, it downloaded a .tar.gz file and built a wheel locally. There were no error messages and everything else in the apps I tested worked OK.

However, I have now just uninstalled that version and reinstalled using:

URL=https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-22.04
/usr/bin/python3 -m pip install -U -f $URL wxPython

And now the WebView examples are all working!

Most likely what happened is that you don’t have the WebKit2 development packages installed, so in that case wxPython will just disable WebView support. On Debian-based systems, that package should be libwebkit2gtk-4.0-dev.

1 Like

You were right, Scott. I just checked in Synaptic Package Manager and libwebkit2gtk-4.0-dev wasn’t installed.

Thanks for your help.

1 Like

Hi all,
I run the same issue on Debian 12 with wxPython 4.2.1 and python 3.11, and this post didn’t solve it.

I installed from sources with the command :
pip wheel -v wxPython-4.2.1.tar.gz 2>&1 | tee build.log

In the build.log I got :

  checking what is the type of the fifth argument of getsockopt... socklen_t
  checking whether we have sockaddr_in6... yes
  configure: WARNING: Disabling wxWebRequest because no backends are available
  checking for linux/joystick.h... yes
  checking for XTST... yes
  checking for PRIVATE_FONTS... yes
.....
  checking for WEBKIT... yes
  checking for CAIRO... yes
  checking for cairo_push_group... yes
  checking for GST... configure: GStreamer 1.7.2+ not available. Not using GstPlayer and falling back to 1.0
  checking for GST... yes

libwebkit2gtk-4.0-dev is installed.
The wheel process of generation runs without error.

The same code is fine on wxPython 4.2.0.

Here is my code using WebView :

import wx.html2 as webview

self.wv = webview.WebView.New(self)

And the error occured :

    self.wv = webview.WebView.New(self)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
NotImplementedError

Any help is welcome, thanks for reading.

Problem solved but no idea on how I reached that.
Sorry for the disturbance.
Have a nice night :slight_smile: