快速应用无法启动

快速应用无法启动

我正在创建一个名为“Surf's Up!”的网络浏览器,并且我已经编写了代码和界面,但是当我尝试运行该应用程序时,出现一条错误消息:

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

代码如下:

# -*- 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)

我需要解决什么问题才能解决这个问题?

答案1

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

基于此,我会尝试将 gtk 版本切换为适合的版本。

尝试:

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

相关内容