Python tries to import packages from the host
See the following output which shows the problem:
$ flatpak run --command=python --filesystem=host:ro org.freedesktop.Platform//23.08
Python 3.11.5 (main, Nov 10 2011, 15:00:00) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python311.zip', '/usr/lib/python3.11', '/usr/lib/python3.11/lib-dynload', '/home/jakob/.local/lib/python3.11/site-packages', '/app/lib/python3.11/site-packages', '/usr/lib/python3.11/site-packages']
>>>
As you can see, ~/.local/lib/python3.11/site-packages
is before /app/lib/python3.11/site-packages
in sys.path
when the Flatpak has access to it. sys.path
is the order, in which Python tries to import packages.
If a Flatpak comes with the Python package foo
, but the User has also installed foo
on his local System, Python will try to import foo
from the local System and not from the Flatpak. This can result in broken Applications, as the version of foo from the local System might not be compatible with the version in the Flatpak.