alfogrillo
alfogrillo

Reputation: 519

Executing Python GIMP scripts on Mac OS

I need help to execute a home made python script that use GIMP libraries on Mac OS. I'm sure the script is ok because it works well on GNU-Linux OS.

What I did:

When I try to execute the script from terminal I get:

ImportError: No module named gimpfu

I don't know how to fix this!

Upvotes: 4

Views: 1530

Answers (1)

xenoid
xenoid

Reputation: 8904

gimpfu is only available when the script is launched from Gimp. There are two cases:

  • The script is a regular plugin, it should contains at least a call to register(...) and a call to main(). This identifies it to Gimp and it can be called from the Gimp UI. Note that the best place to keep it in the plug-ins directory in your Gimp profile, and not the Gimp installation directories. Since you are on OSX, I recommend that you keep the Python file in a directory that you can access easily (and that you backup) and add a soft link to it in your Gimp profile.

  • The script is just a script to be used in batch mode, it doesn't need to be in the plug-ins directory, it must still be called from Gimp which is done by calling Gimp and passing the script as parameters, with a command line such as:

     gimp -idf --batch-interpreter python-fu-eval -b 'import sys; sys.path=["."]+sys.path;import batch;batch.run("./images")' -b 'pdb.gimp_quit(1)'
    

Where:

  • the Python path is extended to include the directory from which the Python file will be loaded: sys.path=["."]+sys.path (here the current directory is used). You can possibly extend the general Python path permanently instead.
  • the script is added to Python: import batch (script is assumed to be in ./batch.py)
  • the run() method in that file is called with any pertinent parameters

Mind the single and double quotes, some for Python, some for your shell interpreter.

Note that calling the script directly from the command line as you did has some merit, many (but not all...) syntax errors are caught at this point, and you don't have to wait for Gimp to start to find these out.

Upvotes: 5

Related Questions