Gimp-Forum.net
Gimp 3 Flatapak Linux PYTHONPATH is empty - 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 3 Flatapak Linux PYTHONPATH is empty (/Thread-Gimp-3-Flatapak-Linux-PYTHONPATH-is-empty)



Gimp 3 Flatapak Linux PYTHONPATH is empty - silenuznowan - 04-03-2025

I'm trying to get a bash script to run after changing folders.

If I explicitly set the path to the python scripts it runs fine.

If I however omit the explicit path, even though the scripts are in my PYTHONPATH they are not recognized when running without
explicitly using sys.path.append

If I try and get the python path from inside the Gimp shell, it reports no key present instead of printing the PYTHONPATH like it does when not in the Gimp shell.

As stated in the title I have the flatpak version so my question is how do I get it to use my current PYTHONPATH?

Also is it possible to use packages, and if so how.  I had a simple package, but when functions were called from a bash script, they would fail with the internal imports in the package failing.  An example is below:


Code:
### This should be the command to start Gimp
GIMP_THREE='flatpak run --user org.gimp.GIMP'

# Start gimp with python-fu batch-interpreter
$GIMP_THREE -i --batch-interpreter=python-fu-eval -b - << EOF

import os
import sys
print("PYTHONPATH = " + os.environ['PYTHONPATH'])


EOF
exit(0)


However if on the command line I load a python script that calls the same methods as the bash script it executes fine.


Code:
 flatpak run --user org.gimp.GIMP -i --batch-interpreter=python-fu-eval -b 'import sys; sys.path=["."]+sys.path;import pytest;pytest.run()'

I feel like it's something simple i'm missing because I'm not a python programmer.  Hopefully someone can help.

Thanks.


RE: Gimp 3 Flatapak Linux PYTHONPATH is empty - Ofnuts - 04-03-2025

flatpak are virtual file system bubbles in which the application is sandboxed. They aren't really fit for general use and are a nightmare when you try to use them together with other apps.

You should peruse this man page that expounds all the nooks and crannies of the flatpak run command. It in particular states that "Flatpak always unsets or overrides the following variables, since their session values are likely to interfere with the functioning of the sandbox: ... PYTHONPATH...". but you can probably set it back with the --env option.


RE: Gimp 3 Flatapak Linux PYTHONPATH is empty - silenuznowan - 04-03-2025

I agree it's likely a flatpak problem but I'm not entirely sure.
If I execute the following
flatpak run --user --command=bash org.gimp.GIMP
I get a bash prompt that has a little package symbol and says org.gimp.Gimp
If I execute
echo $PYTHONPATH
it looks correct.
If I type python the python console loads but with errors:
Could not open PYTHONSTARTUP
FileNotFoundError: [Errno 2] No such file or directory: '/etc/pythonstart'

if I then type
import package_name
it imports the package.
So it doesn't seem to be a problem the flatpak itself finding the modules.


RE: Gimp 3 Flatapak Linux PYTHONPATH is empty - Ofnuts - 04-04-2025

No /etc/pythonstart on my system, nor any PYTHONSTARTUP environmentt variable.


RE: Gimp 3 Flatapak Linux PYTHONPATH is empty - silenuznowan - 04-04-2025

No /etc/pythonstart on my system, nor any PYTHONSTARTUP environmentt variable.
[/quote]

I'm on OpenSuse and i do have a pythonstart file in /etc

But it doesn't look like the culprit, as it is not necessary for python to run.

I just finished building Gimp so I'm going to play around with it and see if the same thing happens. 

As a bonus to building Gimp, it also built the API reference which is pretty nice.

-Jordan

Update: definitely to do with the flatpak, things seem to be working with the newly built version, though I didn't really test it, but it will import the package directly from the console and is usable.

I also noticed that the flatpack throws some warnings, that the version I built does not.

Gtk-Message: 10:28:10.319: Failed to load module "canberra-gtk-module"
[script-fu-test-sphere-v3] The catalog directory does not exist: /app/lib/gimp/3.0/plug-ins/test-sphere-v3/locale
[script-fu-test-sphere-v3] Override method set_i18n() for the plug-in to customize or disable localization.
[script-fu-test-sphere-v3] Localization disabled
Gtk-Message: 10:28:10.734: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:28:11.105: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:28:11.289: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:28:11.416: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:28:11.538: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:28:12.047: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:28:12.307: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:28:12.507: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:28:13.906: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:28:14.323: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:28:23.252: Failed to load module "canberra-gtk-module"

I'm going to try and play with the flatpak to see if it's possible to get the same batch functionality out of it .

Thanks.


RE: Gimp 3 Flatapak Linux PYTHONPATH is empty - Tas_mania - 04-05-2025

On Debian there are libs called 'libcanberra-gtk-module' and 'libcanberra-gtk3-module'.
They translate GTK+ widgets signals to event sounds'.

You may not have these or the libs have a different name.


RE: Gimp 3 Flatapak Linux PYTHONPATH is empty - silenuznowan - 04-05-2025

(04-04-2025, 01:02 AM)Ofnuts Wrote: No /etc/pythonstart on my system, nor any PYTHONSTARTUP environmentt variable.

(04-05-2025, 06:17 AM)Tas_mania Wrote: On Debian there are libs called 'libcanberra-gtk-module' and 'libcanberra-gtk3-module'.
They translate GTK+ widgets signals to event sounds'.

You may not have these or the libs have a different name.

It's the flatpak version that raises those errors.  The flatpak should come with everything necessary because it runs in a sandbox.  Gimp built from source on the same machine does not give these errors.