Question

I'm trying to write a gimp script using pythonfu. However, when I try to run script locally, I get an error

`--> ./vvv.py
Traceback (most recent call last):
  File "./vvv.py", line 5, in <module>
    from gimpfu import *
ImportError: No module named gimpfu

I gather that the script might be only loadable through gimp. However, the script doesn't appear at gimp menus. In that case, how do I get the error output?

Was it helpful?

Solution

depending on your os, you have to look for GIMP plugin's directory, something like:

GIMP 2\lib\gimp\2.0\plug-ins 

and copy your script there. Of Course you have to add registration stuff something like this:

register(
    "python-fu-draw",                                #<- this is plugin name
    N_("brief"),                                     #<- description
    "Long",                                          #<- description
    "name surname",                                  #<- author
    "@Copyright 2013",                               #<- copyright info
    "2013/10/29",                                    #<- creation date
    N_("_Draw..."),                                  #<- label shown in gimp's menu
    "",  #<- kind of image requested from your script (INDEX,RGB,...and so on)
    [                                                #<- input parameters array
        (PF_FILE, "ifile", N_("Color input file"), 'default.txt'),
],
[],                                                  #<- output parameters array (usually empty)
draw,                                                #<- main method to call 
menu="<Image>/Filters/",                             #<- Where add your plugin
domain=("gimp20-python", gimp.locale_directory) 
)

main()                                               #<- don't forget this

Once you copied the script into right directory with right registration stuff you can run GIMP and run your script selecting it in drop down menu you selected in registration stuff. You don't have to run it from a python console. So those wouldn't work:

python myscript.py
./myscript.py
>>> myscript

To debug your script interactively open a python-fu console from gimp:

Filters->Python-fu->Console

Take a look at this web site. Mainly slides are very useful.

While if you want to run your script in a batch mode please take a look at this

OTHER TIPS

This is expected behavior. GIMP's Python plugin has an unusual design: DO NOT call the Python script directly but rather call GIMP which calls your script in turn (this is true both of GUI and command line scripts).


  1. Make sure you register your central function at the end of the script:

    from gimpfu import *
    
    # ... your script ...
    
    args = [(PF_STRING, 'file', 'GlobPattern', '*.*')]   # adjust to your function
    register('my-script', '', '', '', '', '', '', '', args, [], my_function)
    main()   # GIMP's main(), do not write your own!
    
  2. Mark your script executable

    chmod +x my_script.py
    
  3. Copy, move or hardlink your script so that it's in GIMP's plugin directory:

    ln my_script.py ~/.gimp-2.8/plug-ins/my_script.py
    
  4. You can now call GIMP which will call your script (warning: GIMP is a bit slow)

    gimp -i -b '(my-script RUN-NONINTERACTIVE "example.png")' -b '(gimp-quit 0)'
    

    As discussed above, DO NOT do this:

    python my_script.py   # bad!
    

The parentheses are due to it being a Scheme function call. For that same reason you have to replace all hyphens in the list of available functions with underscores (can be found in the GIMP GUI under Help > Procedure Browser).

If you need an example script, check out the documentation or my script.

A common cause of Python plugins silently not appearing in GIMP is syntax errors. A quick, scriptable way to check:

python -m py_compile vvv.py

On Windows platforms, a successful compile will return an %errorlevel% of 0.

Paraphrasing the original post: I wrote a Python GIMP plugin and installed it in the proper place, but it doesn't appear in GIMP's Filter menu, so how do I debug it?

The most common cause is that you didn't give execute permission on the plugin's source (.py) file when you copied it to the proper place. (It's a known quirk of GIMP that it won't read Python plugin source that doesn't have execute permission.)

Another question might be: my plugin appears in the GIMP Filter menu, but it silently doesn't work as I expect, how do I debug it?

You can either start GIMP in a console (a terminal) so that any debugging print from your plugin goes to the console, or use Filters>Python-Fu>Console as suggested in another answer.

If your plugin crashes, the GIMP GUI will show you the traceback, or it will appear in a console you started GIMP in.

Another question might be: can I debug Python scripts that import PyGimp modules? (most commonly gimpfu, which is an omnibus module that imports other PyGimp modules.) For example, you have a Python module for use by a GIMP Python plugin, and you want to test portions of it (say, doctest it) without starting GIMP.

You might be able to install PyGimp (into the Python directories) by the standard: download PyGimp, .configure, make, make install. (I haven't tried that and could not easily find a downloadable source package for PyGimp.) Usually, the PyGimp modules are installed with GIMP, and not installed in the Python directories (GIMP just futzes with PYTHON_PATH when it starts a Python interpreter so that the PyGimp modules are found?) Or in your environment (of the shell or your IDE) you could change PYTHON_PATH so that it includes the subdirectory of your GIMP installation that holds the PyGimp modules.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top