Python plugin on U20 - interpreter not included properly

According to the docs: The python plugin

Use of python3- in stage-packages will force the inclusion of the python interpreter.

If I create the following over simplified snopcraft.yaml

name: test-thing
base: core20
version: '0.0.0'
summary: Test thing
description: |
    ..for testing _things_

grade: devel
confinement: devmode

    command: bin/test-thing
      GI_TYPELIB_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/girepository-1.0

    plugin: dump
    source: test-thing
      test-thing : bin/
    plugin: python
      - python3-gi
      - gir1.2-snapd-1

I should get a copy of python included in my snap as far as I understand.

However, it does not inlcude the interpret, but a symlink that resolves to the base snap. Hence, modules are not loaded from the dist-packages in the snap.

This is how the snap looks if I shell into the snap using snap run --shell test-thing :

root@ubuntu:~# which python3
root@ubuntu:~# ls -al /snap/test-thing/x2/bin/python3
lrwxrwxrwx 1 root root 16 Oct 13 20:20 /snap/test-thing/x2/bin/python3 -> /usr/bin/python3

Any idea what’s going on and how I can fix this ?


1 Like

Hmmmm, extra info.

If I change the snapcraft definition to install package using pip with an override-build, the symlink is the same, but the module in dis-packages in the snap seem to be found !

    override-build: |
      snapcraftctl build
      pip3 install wheel
      pip3 install pycairo
      pip3 install PyGObject

… vs …

      - python3-gi

So, while I have a working method, I wouls still like to know the different. Why do pip package work [ the are importable modules ] , but python debs don’t work [ they are not importable modules ].


Typically snapcraft won’t include packages that are found in the base snap unless explicitly requested. You need more packages to include everything in your snap.

Here is an example of a fully staged python:

Here is an example of supporting python stage-packages using PYTHONPATH:

The documentation for the python plugin seems to suggest it should be included automatically, if you specify a python3- prefixed package in stage-packages - that’s my main source of confusion :slight_smile:

Perhaps it’s a bug in that case.

Thanks for the tip on PYTHONPATH @cjp256 - that looks like the I’m missing when the interpreter from base is used, I should of just tried that ! :slight_smile:

Cheers, Just

1 Like