0

I'm creating a web-browser named "Surf's Up!", and I have programmed the code and the interface, but when I try to run the app, an error message appears:

Traceback (most recent call last):
File "bin/surfs-up", line 32, in <module>
import surfs_up
File "/home/owner/surfs-up/surfs_up/__init__.py", line 14, in <module>
from surfs_up import SurfsUpWindow
File "/home/owner/surfs-up/surfs_up/SurfsUpWindow.py", line 10, in <module>
from gi.repository import Gtk, WebKit # pylint: disable=E0611
File "/usr/lib/python2.7/dist-packages/gi/importer.py", line 76, in load_module
dynamic_module._load()
File "/usr/lib/python2.7/dist-packages/gi/module.py", line 222, in _load
version)
File "/usr/lib/python2.7/dist-packages/gi/module.py", line 90, in __init__
repository.require(namespace, version)
gi.RepositoryError: Requiring namespace 'Gtk' version '2.0', but '3.0' is already loaded

The code is as follows:

# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# This file is in the public domain
### END LICENSE

import gettext
from gettext import gettext as _
gettext.textdomain('surfs-up')

from gi.repository import Gtk, WebKit # pylint: disable=E0611
import logging
logger = logging.getLogger('surfs_up')

from surfs_up_lib import Window
from surfs_up.AboutSurfsUpDialog import AboutSurfsUpDialog
from surfs_up.PreferencesSurfsUpDialog import PreferencesSurfsUpDialog

# See surfs_up_lib.Window.py for more details about how this class works
class SurfsUpWindow(Window):
    __gtype_name__ = "SurfsUpWindow"

    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the main window"""
        super(SurfsUpWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutSurfsUpDialog
        self.PreferencesDialog = PreferencesSurfsUpDialog

        # Code for other initialization actions should be added here.

        self.refresh = self.builder.get_object("refresh")
        self.urltext = self.builder.get_object("urltext")
        self.scroll = self.builder.get_object("scroll")
        self.toolbar = self.builder.get_object("toolbar")

        context = self.toolbar.get_style_context()
        context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)

        self.webview = WebKit.WebView()

        self.scroll.add(self.webview)
        self.webview.show()

    def on_refresh_clicked(self, widget):
        print "Refreshing page.................................."
        self.webview.reload()
    def on_urltext_activate(self, widget):
        url = widget.get_text()
        print url
        self.webview.open(url)

What do I need to fix to resolve the situation?

1 Answer 1

0
gi.RepositoryError: Requiring namespace 'Gtk' version '2.0', but '3.0' is already loaded

Based on that, I would try to switch the gtk version to the one that fits.

Try:

....
from gi.repository import Gtk, WebKit # pylint: disable=E0611    
Gtk.switch
....

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .