Gimp, Python versions, and flatpak - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions) +---- Thread: Gimp, Python versions, and flatpak (/Thread-Gimp-Python-versions-and-flatpak--9658) |
Gimp, Python versions, and flatpak - chrispanda - 01-04-2025 I've been writing a python plugin for gimp, using RC2 installed with flatpak. It's been a steep learning curve but i have it working. I now want to take some of that code and put it in a standalone python app, since it doesn't actually need the gimp interface My idea was to simply use the system python and import the necessary gi repository files - but they are already installed inside the flatpak Is there a way to use the python version installed with gimp and flatpak from outside the flatpak sandbox? Or should I copy the gi repository files into the system python directories, and if so where? Many thanks RE: Gimp, Python versions, and flatpak - Ofnuts - 01-04-2025 (copied my answer from the question elsewhere) You can't do this. Your Python code relies on the whole Gimp executable for most of its functionality. The gi repos are merely interfaces to code in Gimp, Gegl and Babl. In fact the code in the Gimp import only works when its caller (your code) is called from Gimp... You could have more luck with just Gegl/Babl. You can run Gimp without a UI (-i, --no-interface) and it is likely possible to run flatpak-Gimp in batch mode (even if the start incantation is likely a bit different). But installing Gimp form a .deb would be a lot easier, and .deb Babl/Gegl would be a requirement if you can skirt Gimp. You can get 3.00 RC2 in .deb format from here: https://launchpad.net/~mati75/+archive/ubuntu/gimp30 But very often, I see people writing very complicated scripts around Gimp to do rather simple things that are better done with shell scripts around ImageMagick or with Python and image processing libraries (pillow, openCV...). RE: Gimp, Python versions, and flatpak - chrispanda - 01-04-2025 Im sorry to have made you repeat yourself - I did find this answer eventually. I've tried running a simple batch process by loading a 'hello world' script into the scripts directory and starting it with Code: flatpak run org.gimp.GIMP//beta --batch-interpreter python-fu-eval -i -b 'hello' --verbose This fires up the script interpreter ok, but then fails with the error message: Code: GIMP-Error: Unable to run plug-in "hello.py" The plugin code: Code: #!/usr/bin/env python3 which I thought should run since its running as a batch process. What I discovered does work is Code: flatpak run org.gimp.GIMP//beta --batch-interpreter python-fu-eval -i -b 'print("hello")' so it looks as if the -b instruction is passing the argument directly to the interpreter, not treating it as a file name. I'm stuck now. I appreciate your suggestion that there might be simpler ways of doing what I'm trying to do, but to be honest I'm so nearly finished it seems a waste to start again. Just need to get over this last hurdle! RE: Gimp, Python versions, and flatpak - Ofnuts - 01-05-2025 See https://stackoverflow.com/questions/44430081/how-to-run-python-scripts-using-gimpfu-from-windows-command-line/44435560#44435560 RE: Gimp, Python versions, and flatpak - chrispanda - 01-05-2025 Thanks for all your help with this. I have it working nicely now. The full setup is I have a script that watches for changes in a mailbox, downloads incoming files and strips off any attachments. When it has found a new image it calls the batch file to process this image - basically resize it and put it into a mask (premade templat.xcf) to print out a badge. The xcf file is then saved so that a user can open it, slide the image around in the mask, resize if necessary, and print. Just so that others have some more code samples for gimp 3.0 I'll upload the key section here and hope this helps someone else. Thanks again Code: for fname in glob.glob(os.path.join(imagepath, '*.*')): |