python can't import gimpfu
Solution 1
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
Solution 2
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).
-
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!
-
Mark your script executable
chmod +x my_script.py
-
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
-
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.
Yotam
Updated on June 14, 2022Comments
-
Yotam almost 2 years
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?