Python library 'clipboard' is not installed.

Probleme bei der Installation?
Antworten
MacQGIS
User
Beiträge: 2
Registriert: Freitag 15. Juli 2022, 08:02

Sehr geehrte Damen und Herren,

Ich arbeite mit QGIS und hatte noch nicht das vergnügen mit Python zu arbeiten. Ich habe weder die Konsole aufgerufen oder etwas mit Python zu tun gehbt.
Um so merkwürdiger finde ich es das ich jetzt eine Fehlermeldung bekomme die lautet:
Python library 'clipboard' is not installed. To install it, follow these instructions: https://landscapearchaeology.org/2018/i ... r-windows/
Selbst wenn ich versuche die Hilfe bzw. die Install Anweisungen bei landscapearchaeology anzuwenden bekomme ich nur weiter Fehlermeldungen.

Kenn sich wer mit QGIS in Verbindung mit Python aus und kann hier helfen?

from qgis import processing
try:
import clipboard as c
except:
raise Exception("Python library 'clipboard' is not installed. To install it, follow these instructions: https://landscapearchaeology.org/2018/i ... r-windows/")

# Initialize Qt resources from file resources.py
from .resources import *
# Import the code for the dialog
from .return_pyqgis_algorithm_dialog import ReturnPyQGISAlgorithmDialog
import os.path


class ReturnPyQGISAlgorithm:
"""QGIS Plugin Implementation."""

def __init__(self, iface):
"""Constructor.

:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'ReturnPyQGISAlgorithm_{}.qm'.format(locale))

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
QCoreApplication.installTranslator(self.translator)

# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&Return PyQGIS Algorithm')

# Check if plugin was started the first time in current QGIS session
# Must be set in initGui() to survive plugin reloads
self.first_start = None

# noinspection PyMethodMayBeStatic
def tr(self, message):
"""Get the translation for a string using Qt translation API.

We implement this ourselves since we do not inherit QObject.

:param message: String for translation.
:type message: str, QString

:returns: Translated version of message.
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('ReturnPyQGISAlgorithm', message)


def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None):
"""Add a toolbar icon to the toolbar.

:param icon_path: Path to the icon for this action. Can be a resource
path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
:type icon_path: str

:param text: Text that should be shown in menu items for this action.
:type text: str

:param callback: Function to be called when the action is triggered.
:type callback: function

:param enabled_flag: A flag indicating if the action should be enabled
by default. Defaults to True.
:type enabled_flag: bool

:param add_to_menu: Flag indicating whether the action should also
be added to the menu. Defaults to True.
:type add_to_menu: bool

:param add_to_toolbar: Flag indicating whether the action should also
be added to the toolbar. Defaults to True.
:type add_to_toolbar: bool

:param status_tip: Optional text to show in a popup when mouse pointer
hovers over the action.
:type status_tip: str

:param parent: Parent widget for the new action. Defaults None.
:type parent: QWidget

:param whats_this: Optional text to show in the status bar when the
mouse pointer hovers over the action.

:returns: The action that was created. Note that the action is also
added to self.actions list.
:rtype: QAction
"""

icon = QIcon(icon_path)
action = QAction(icon, text, parent)
self.iface.registerMainWindowAction(action, "Ctrl+Alt+Space")
action.triggered.connect(callback)
action.setEnabled(enabled_flag)

if status_tip is not None:
action.setStatusTip(status_tip)

if whats_this is not None:
action.setWhatsThis(whats_this)

if add_to_toolbar:
# Adds plugin icon to Plugins toolbar
self.iface.addToolBarIcon(action)

if add_to_menu:
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."""

icon_path = ':/plugins/return_pyqgis_algorithm/icon.png'
self.add_action(
icon_path,
text=self.tr(u'Copy PyQGIS Algorithm Code'),
callback=self.run,
parent=self.iface.mainWindow())

# will be set False in run()
self.first_start = True


def unload(self):
"""Removes the plugin menu item and icon from QGIS GUI."""
for action in self.actions:
self.iface.removePluginMenu(
self.tr(u'&Return PyQGIS Algorithm'),
action)
self.iface.removeToolBarIcon(action)

def returnAlg(self):
# get params
returnResultStr = ''
getOutputStr = ''

params = {}
for param in self.alg.parameterDefinitions():
params[param.name()] = param.defaultValue()

if self.dlg.virtualLayerCheckBox.isChecked():
returnResultStr = 'res = '
getOutputStr = '\noutput = res["OUTPUT"]'
params["OUTPUT"] = "TEMPORARY_OUTPUT"

paramsStr = str(params)
paramsStr = paramsStr.replace(", ", ",\\\n\t").replace("{", "{\n\t").replace("}", "\n}")
if 'native' not in self.alg.id():
paramsStr = paramsStr.replace("'TEMPORARY_OUTPUT'", 'QgsProcessing.TEMPORARY_OUTPUT')
function = f'{returnResultStr}processing.run("{self.alg.id()}", {paramsStr}){getOutputStr}'

c.copy(function)
message_function = function.replace("\t", " ")
QMessageBox.information(None, "QGIS Algorithm", "✅ Function copied to clipboard\n\n" + message_function)

def run(self):
"""Run method that performs all the real work"""

# Create the dialog with elements (after translation) and keep reference
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
if self.first_start == True:
self.first_start = False
self.dlg = ReturnPyQGISAlgorithmDialog()
self.keyErrorCount = 0

# auto complete options
labelsToAlgs = {}
algSelection = []
for alg in QgsApplication.processingRegistry().algorithms():
name = alg.displayName()
# name = alg.displayName()
provider = alg.provider().name()
label = f"{name} ({provider})"
labelsToAlgs[label] = alg
algSelection.append(label)
completer = QCompleter(algSelection)

# create line edit and add auto complete
completer.setFilterMode(Qt.MatchContains)
self.dlg.lineEdit.setCompleter(completer)

# show the dialog
self.dlg.show()
self.dlg.lineEdit.setFocus()
# Run the dialog event loop
result = self.dlg.exec_()
# See if OK was pressed
if result:
# Do something useful here - delete the line containing pass and
# substitute with your code.
text = self.dlg.lineEdit.text()
try:
self.alg = labelsToAlgs[text]
self.returnAlg()
self.dlg.lineEdit.setText("")
except KeyError:
QMessageBox.critical(None, "Error", f"You must enter an existing algorithm in the text box. You entered: {text}")
self.dlg.lineEdit.setText("")
self.keyErrorCount += 1
if self.keyErrorCount < 5:
self.run()
else:
# safegaurding against infinite input bug
self.keyErrorCount = 0
pass
Sirius3
User
Beiträge: 17741
Registriert: Sonntag 21. Oktober 2012, 17:20

Warum machst Du das so kompliziert über ein weiteres Modul?
Nutz doch einfach das Clipboard von Qt:

Code: Alles auswählen

QgsApplication.clipboard().setText(function)
__deets__
User
Beiträge: 14528
Registriert: Mittwoch 14. Oktober 2015, 14:29

@Sirius3: der TE macht da gar nix, der installiert nur Plugins.

@MacQGIS: was sind denn die weiteren Fehlermeldungen?
MacQGIS
User
Beiträge: 2
Registriert: Freitag 15. Juli 2022, 08:02

@von __deets__

schau mal ob das hilft

Variables
QAction = (wrappertype) < class 'PyQt5.QtWidgets.QAction'>
module_= (str) 'PyQt5.OtWidgets'
str_= (str) Py@t5.OtWidgets
doc_= (str) 'QAction (parent: QObject = None)\nQAction(str, parent: Q0bject = None)\nQAction((
str = (str} QAction(parent: Q0bject = None)
QAction(str, parent: QObject = None)
QAction(Qlcon, str, parent: QObject = None)
ActionEvent = (enumtype} « class 'PyQt5.QtWidgets.QAction.ActionEvent'>
module_ = (str) 'PyQt5.QtWidgets'
str
= (str) PyQt5.QtWidgets
dict
= (getset descriptor} « attribute'
dict ' of 'ActionEvent' objects>
doc_
_ = (NoneType) None
reduce
= (method descriptor) «method '_pickle_enum' of 'ActionEvent' objects>
MenuRole = (enumtype} «class 'PyQt5.QtWidgets.QAction.MenuRole'>
module
_= (str) 'PyQt5.QtWidgets'
_dict_ = (getset descriptor) « attribute'
dict ' of 'MenuRole' objects»
doc
= (NoneType) None
_reduce_ = (method_descriptor) <method '_pickle_ enum' of 'MenuRole' objects»
Priority = (enumtype) <class 'PyQt5.QtWidgets.QAction.Priority'>
module_ = (str) 'PyQt5.QtWidgets'
dict
_= (getset_ descriptor) éattribute
dict ' of 'Priority' objects>
doc_ = (NoneType) None
reduce_= (method descriptor) «method '_pickle _enum' of 'Priority' objects>
actionGroup = (methoddescriptor) < built-in method actionGroup>
activate = (methoddescriptor) « built-in method activate»
associatedGraphicsWidgets = (methoddescriptor) &built-in method associatedGraphicsWidgets>
associatedWidgets = (methoddescriptor) «built-in method associatedWidgets>
autoRepeat = (methoddescriptor) «built-in method autoRepeat>
childEvent = (methoddescriptor) «built-in method childEvent>
connectNotify = (methoddescriptor} <built-in method connectNotify>
customEvent = (methoddescriptor} «built-in method customEvent>
data = methoddescriptor! «built-in method data>
disconnectNotify = (methoddescriptor} <built-in method disconnectNotify>
event = (methoddescriptor} «built-in method event>
font = (methoddescriptor} <built-in method font>
hover = (methoddescriptor) «built-in method hover>
icon = (methoddescriptor} <built-in method icon>
iconText = (methoddescriptor} «built-in method icon Text>
isCheckable = (methoddescriptor} «built-in method isCheckable>
isChecked = (methoddescriptor} <built-in method isChecked>
isEnabled = (methoddescriptor) «built-in method isEnabled>
islconVisiblelnMenu = (methoddescriptor} «built-in method islconVisiblelnMenu>
isSeparator = (methoddescriptor} «built-in method isSeparator>
isShortcutVisiblelnContextMenu={(methoddescriptor}<built-inmethodisShortcutVisiblelnContextMenu>
isSignalConnected = (methoddescriptor} «built-in method isSignalConnected>
isVisible = (methoddescriptor} «built-in method isVisible>
menu = (methoddescriptor} « built-in method menu>
menuRole = (methoddescriptor} «built-in method menuRole>
__deets__
User
Beiträge: 14528
Registriert: Mittwoch 14. Oktober 2015, 14:29

Nein, das hilft leider nicht. Ich sehe jedenfalls nicht die Anweisungen, und ihre Fehler, die auf der Webseite dokumentiert sind, mit der man fehlende Pakete installiert. Das ist ja nunmal die Aufgabe.
Antworten