Experimental Python interpreter snap

James Henstridge james.henstridge at canonical.com
Wed Mar 1 00:37:08 UTC 2017

On 23 February 2017 at 19:34, Stuart Bishop <stuart.bishop at canonical.com> wrote:
> On 23 February 2017 at 14:45, James Henstridge
> <james.henstridge at canonical.com> wrote:
>> So if I installed a package to $SNAP_USER_DATA for my
>> "python36-jamesh.python3" interpreter, the files would end up
>> somewhere under ~/snap/python36-jamesh/.
>> If we then look at my simple hello-world example snap that uses the
>> content interface to access the interpreter, $SNAP_USER_DATA now
>> points to a location under ~/snap/hello-world/.  So it wouldn't see
>> the additional packages installed for "python36-jamesh.python3".  In
>> fact, the hello-world snap doesn't even have permission to read files
>> under ~/snap/python36-jamesh, even if I put that directory on
>> sys.path.
> Yes, exactly. If I use the python36-jamesh.python3 interpreter from my
> main shell, I can pip install libraries into $SNAP_USER_DATA and use
> them. They will not be seen or cause conflicts if I use the
> /usr/bin/python3, which is what I'm suggesting is an improvement. And
> they will not be seen by or cause conflicts with snaps using the
> content interface, no matter if they are confined or classic, which is
> also a good thing because they will be embedding their dependencies.

I put together a new build of my snap that should cover the developer
use case a bit better.  You can install it in an unconfined mode with
the following command:

    $ snap install --edge --classic python36-jamesh
    python36-jamesh (edge) 3.6.0 from 'jamesh' installed

It has a usable pip3 (provided you do a --user install):

    $ python36-jamesh.pip3 install --user django
    Collecting django
      Downloading Django-1.10.5-py2.py3-none-any.whl (6.8MB)
        100% |################################| 6.8MB 173kB/s
    Installing collected packages: django
    Successfully installed django-1.10.5

Which results in the package being installed to the python36-jamesh
package's $SNAP_USER_COMMON directory:

    $ python36-jamesh.python3
    Python 3.6.0 (default, Feb 28 2017, 23:29:31)
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import django
    >>> django.__file__

When used via content interface by other snaps, it should act the same
as the previous build.  And from a security perspective, it doesn't
matter whether the interpreter is installed with --classic or not,
since it will use the plug snap's policies when used via content

I also managed to get this update to build across all of i386, amd64,
armhf, and arm64 by building with a backported version of patchelf:
the package was missing for armhf on xenial due to a test failure.


More information about the Snapcraft mailing list