luke1985
luke1985

Reputation: 2354

Error "ImportError: No module named gimpfu" in GIMP plugin

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?

Upvotes: 4

Views: 3822

Answers (1)

xenoid
xenoid

Reputation: 8914

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.

Upvotes: 5

Related Questions