Permission for snap to install site-packages in python

Hello,

I have an application where the snap application itself should install pypi packages depending on what component the user wants to install. However I keep getting the error:

ERROR: Could not install packages due to an EnvironmentError: [Errno 30] Read-only file system: ‘/snap/snap_name/x1/usr/lib/python3.8/site-packages/package_name’

I looked at using the interfaces system-files, content and layouts and tried both system-files and content but I don’t think that this is what they are ment to do. Not really sure how it could work with layouts.

One way of doing it could be to install the packages in $SNAP_USER_COMMON or the like and then add that to the PYTHONPATH variable. Only problem is that it is an open source software with a rather large code base so changing the default installation path to for example $SNAP_USER_DATA could be troublesome.

The easiest way would probably be to give permission to the application to install site-packages in the python directory but I don’t know how to do that.

Any help would be much appreciated!

all open source software makes this easy, if not trivial. Especially python-based projects where there are at least three different places things usually get installed. How is it troublesome in this case?

Thank you for your response.

Well I suppose it is not that troublesome but compared to the other option it could imply more code changes. Anyhow, I’ll have to dig a little deeper into that option I think.

Although it feels like the installed python packages also belong in the python distribution site-packages. But there is no way of giving the permissions, using for example an interface?

There is no interface for that.
Also, in core, it’s dist-packages not site-packages, as it is in any debian-based distro.
Further, I don’t want anything that’s not my package manager putting things in dist-packages.
Lastly, why are you trying to install libraries at runtime instead of shipping the alternatives in the package and switching between them dynamically?