【发布时间】: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