【问题标题】:Error "ImportError: No module named gimpfu" in GIMP pluginGIMP 插件中出现错误“ImportError:没有名为 gimpfu 的模块”
【发布时间】:2021-11-14 10:22:20
【问题描述】:

我正在尝试为 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()

我已将其放入名为“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

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

【问题讨论】:

  • 你用的是哪个python 2还是3?如果使用2,请切换到3。如果使用3,请检查shebang中的exe指向的版本。
  • @kiner_shah 我使用的是版本 3。exe 指向 /usr/bin/python3.8
  • 运行python3然后尝试导入gimpfu库,如果抛出一些错误,gimpfu没有安装。
  • @kiner_shah 我知道它没有安装,因为这是一个内部 GIMP 模块。我在 Windows 10 上对此脚本没有任何问题,该脚本由 GIMP 提供。如果不使用不同的 shebang 可执行文件或安装 gimpfu 模块,我无法解决这个问题,我不知道从哪里得到。
  • 这能回答你的问题吗? python can't import gimpfu

标签: python plugins gimp


【解决方案1】:

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

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

要让 Python 在 Gimp 中运行,您必须

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

另一种解决方案是安装 Gimp 的 flatpak 版本,它自带 Python 支持(链接 on this page)。

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

【讨论】:

  • 安装 flatpak 版本解决了这个问题。谢谢!
猜你喜欢
  • 2016-11-03
  • 2023-03-03
  • 1970-01-01
  • 2017-10-23
  • 2019-07-31
  • 1970-01-01
  • 2019-07-30
  • 2018-12-08
  • 2014-02-08
相关资源
最近更新 更多