3

I'm trying to write a plugin for GIMP, which looks like following:

#!/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()

I've put it in a file called "export_layers_as_images.py" and moved the file into "~/.config/GIMP/2.10/plug-ins" directory.

I'm using Linux Mint OS. When I start GIMP, I get the following error:

  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

How can I solve this issue? I have an idea that the Python interpreter at the shebang is wrong, and if so, what do I use?

luke1985
  • 2,281
  • 1
  • 21
  • 34
  • Which python are you using 2 or 3? If using 2, please switch to 3. If using 3, please check what version the exe in the shebang points to. – kiner_shah Nov 14 '21 at 10:24
  • @kiner_shah I'm using version 3. The exe points to /usr/bin/python3.8 – luke1985 Nov 14 '21 at 10:27
  • Run `python3` and in then just try importing `gimpfu` library, if some errors are thrown, `gimpfu` isn't installed. – kiner_shah Nov 14 '21 at 10:28
  • @kiner_shah I know that it's not installed since this is an internal GIMP module. I have no issuess with this script on Windows 10, where the script is provided by GIMP. I can't solve the issue without either using a different shebang executable or by installing the gimpfu module, which I don't know where to get from. – luke1985 Nov 14 '21 at 10:30
  • Does this answer your question? [python can't import gimpfu](https://stackoverflow.com/questions/18986723/python-cant-import-gimpfu) – kiner_shah Nov 14 '21 at 10:31
  • @kiner_shah No, since I'm not trying to run the script locally using "python3 script.py" – luke1985 Nov 14 '21 at 10:35
  • Did you read the answer? Maybe it applies to your situation. – kiner_shah Nov 14 '21 at 10:37
  • I've read them, they are not of any use for me. – luke1985 Nov 14 '21 at 10:41

1 Answers1

4

Current Gimp (Gimp 2.10 or before) requires Python v2.

Many recent distros (Ubuntu 20.04 and later, and their derivatives) no longer install Python2 by default since it is officially deprecated.

To get Python working in Gimp, you have to

  1. Install Python V2 (which still likely exists as a package in your package manager)
  2. Install the Python support for your Gimp (which is in a separate gimp-python package). It is possible to steal the package(s) from a distro where Python v2 was still supported? see here for instance.

Another solution is to install a flatpak version of Gimp that comes with its own Python support (link on this page).

A third solution is to compile your own Gimp from source.

xenoid
  • 8,396
  • 3
  • 23
  • 49