GIMP 插件中出现错误“ImportError:没有名为 gimpfu 的模块”

luk*_*985 4 python plugins gimp

我正在尝试为 GIMP 编写一个插件,如下所示:

#!/usr/bin/python3
import os
from gimpfu import *

def run(image, drawable, directory):
    
    layers = image.layers
    for layer in layers:
        if pdb.gimp_item_is_group(layer):  # Check if the layer is a GroupLayer
            filename = directory + os.sep + layer.name + ".png"
            pdb.file_png_save(image, layer, filename, filename, 0, 9, 1,1,1,1,1)
            # Destroy the new image:
          
    
register(
    "export-layer-groups",
    "Export layers",
    "Export layer groups as png images",
    "Lukasz Michalczyk",
    "LM",
    "2020",
    "<Image>/File/Export layer groups..",
    "*",
    [
        (PF_DIRNAME, "directory", "Directory", None),
    ],
    [],
    run)
    
main()
Run Code Online (Sandbox Code Playgroud)

我将其放入名为“export_layers_as_images.py”的文件中,并将该文件移至“~/.config/GIMP/2.10/plug-ins”目录中。

我正在使用 Linux Mint 操作系统。当我启动 GIMP 时,出现以下错误:

  Traceback (most recent call last):
  File "/home/lukasz/.config/GIMP/2.10/plug-ins/export_layers_as_images.py", line 3, in <module>
    from gimpfu import *
ImportError: No module named gimpfu
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?我有一个想法,shebang 的 Python 解释器是错误的,如果是这样,我应该使用什么?

xen*_*oid 5

当前的 Gimp(Gimp 2.10 或之前版本)需要 Python v2。

许多最近的发行版(Ubuntu 20.04 及更高版本及其衍生版本)不再默认安装 Python2,因为它已被正式弃用。

要让 Python 在 Gimp 中工作,你必须

  1. 安装 Python V2(它仍然可能作为包存在于包管理器中)
  2. 安装 Gimp 的 Python 支持(位于单独的gimp-python包中)。是否可以从仍支持 Python v2 的发行版中窃取软件包?例如,请参见此处。

另一个解决方案是安装 Gimp 的 flatpak 版本,它带有自己的 Python 支持(此页面上的链接)。

第三种解决方案是从源代码编译您自己的 Gimp。