16

When I try to import Webkit from gi.repository, it gives an ImportError:

from gi.repository import Webkit
ERROR:root:Could not find any typelib for Webkit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name Webkit

What am I doing wrong?

Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
Abhilash Nanda
  • 339
  • 2
  • 4
  • 13

1 Answers1

34

Your error seems a typo and the library is not found for that.

You have to put "WebKit" instead of "Webkit".

Additionaly if you use Ubuntu check the library existence with:

$ locate girepository | grep WebKit
/usr/lib/girepository-1.0/WebKit-3.0.typelib

If doesn't exist you need install the package gir1.2-webkit-3.0:

# apt-get install gir1.2-webkit-3.0 

Then on python script:

import gi
gi.require_version('WebKit', '3.0')
from gi.repository import WebKit

Note: For Ubuntu 17.10 or later, the library seems called WebKit2. Which could be installed:

$sudo apt-get install gir1.2-webkit2-4.0

And found in:

$ locate girepository | grep WebKit
/usr/lib/x86_64-linux-gnu/girepository-1.0/WebKit2-4.0.typelib

You can use in Python like:

import gi
gi.require_version('WebKit2', '4.0')
from gi.repository import WebKit2
shakaran
  • 10,612
  • 2
  • 29
  • 46
  • It seems on Ubuntu 17.10 and later it should be gir1.2-webkit2-4.0, so `sudo apt-get install gir1.2-webkit2-4.0` should work... though unfortunately you can't import Webkit even with it installed. – NoBugs Oct 14 '17 at 04:29
  • 1
    Actually you can, but only using gi repository `WebKit2` module which is quite different from the version we had before. – NoBugs Oct 14 '17 at 05:34
  • Thanks I add as note in the reply too, this was a change in more than 6 years ;) – shakaran Oct 15 '17 at 13:26