Установите protobuf==3.13.0 для QGis 3.14.16 под Ubuntu 18.04

Запуская QGis 3.14.16, я бы хотел открыть личный плагин, который использует protobuf. Под Windows у меня есть protobuf==3.13.0, и он работает. Под Linux нельзя сказать, что плагину требуется 3.13.0, но у QGis есть 3.0.0.

Как тогда я могу установить protobuf 3.0.0 для QGis?

В консоли Python я пробовал:

import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
print(installed_packages_list)

и оно показывает protobuf==3.13.0. Странный.

Я старался

import pip
pip.main(["install", "protobuf==3.13.0"])

но все же я получаю окна сообщений о том, что QGis обнаружил 3.0.0.

Или есть способ использовать виртуальную среду python для QGis?

Вы можете легко проверить это, создав три файла в новом каталоге protobuf_tester

- Windows: C:\Users\USERNAME\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\protobuf_tester
- Linux: /lhome/USERNAME/.local/share/QGIS/QGIS3/profiles/default/python/plugins/protobuf_tester

__init__.py

# -*- coding: utf-8 -*-
from .protobuf_tester import ProtobufTester


def classFactory(iface):
    return ProtobufTester(iface)

metadata.txt

# This file contains metadata for your plugin. Since 
# version 2.0 of QGIS this is the proper way to supply 
# information about a plugin. The old method of 
# embedding metadata in __init__.py will 
# is no longer supported since version 2.0.

# This file should be included when you package your plugin.# Mandatory items:

[general]
name=ProtobufTester
qgisMinimumVersion=3.0
description=Tries to import the protobuf modules
version=0.1
author=Roland
about=Since it prints results to the python console, please open the python console first via the extension menu. In case of an google protobuf-error you'll get a message window, in case of success you don't.

# Tags are comma separated with spaces allowed
tags=python,protobuf,qgis

experimental=True

# deprecated flag (applies to the whole plugin, not just a single version)
deprecated=False

protobuf_tester.py

# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import QAction


class ProtobufTester:

    def __init__(self, iface):
        self.iface = iface

        self.menu = u'&Protobuf Tester'

        self.toolbar = self.iface.addToolBar(u'ProtobufTester')
        self.toolbar.setObjectName(u'ProtobufTester')

        self.actions = []

    def add_action(self, text, callback, parent=None):
        """Helper function to add actions to the menu and the toolbar"""

        action = QAction(text, parent)
        action.triggered.connect(callback)
        action.setEnabled(True)
        self.toolbar.addAction(action)
        self.iface.addPluginToMenu(self.menu, action)
        self.actions.append(action)

        return action

    def initGui(self):
        """Create the menu entries and toolbar icons inside the QGIS GUI."""

        self.add_action(text=u'Import google.protobuf', callback=self.run_version, parent=self.iface.mainWindow())
        self.add_action(text=u'Import descriptor', callback=self.run_descriptor, parent=self.iface.mainWindow())

    def unload(self):
        """Removes the plugin menu item and icon from QGIS GUI."""

        for action in self.actions:
            self.iface.removePluginMenu(
                u'&Protobuf Tester',
                action)
            self.iface.removeToolBarIcon(action)
        # remove the toolbar
        del self.toolbar

    # --------------------------------------------------------------------------

    def run_version(self):
        """Just show the current google-protobuf-version"""

        print("Starting run_version")
        import google.protobuf

        print("- Protobuf-Version: %s" % google.protobuf.__version__)

    def run_descriptor(self):
        """From the same google protobuf import the descriptor"""

        print("Starting run_descriptor")

        from google.protobuf import descriptor as _descriptor

        print("run_descriptor finished")

Чтобы проверить это, запустите QGis, откройте консоль python через меню расширений и запустите две точки меню под записью ProtobufTester.

Если вы получаете сообщение об ошибке, как и я (обнаружение protobuf 3.0.0, но требуется 3.13.0), что я могу сделать, чтобы решить эту проблему?

0 ответов

Другие вопросы по тегам