[Solved] Problem with distutils.sysconfig package when creating a snap package for Guake


I’m trying to create a snap package for Guake terminal, but have problem with adding python runtime dependencies.

With this snapcraft.yaml file:

name: guake # you probably want to 'snapcraft register ’
base: core18
version: ‘3.6.3’
summary: Top-down terminal for Gnome, inspired by the terminal used in Quake
description: |
Guake is a drop-down terminal for GNOME Desktop Environment,
so you just need to press a key to invoke him, and press again to hide.
Guake supports hotkeys, tabs, background transparent, etc.

grade: devel # must be ‘stable’ to release into candidate/stable channels
confinement: devmode # use ‘strict’ once you have the right plugs and slots

command: usr/local/bin/guake
PYTHONPATH: $PYTHONPATH:$SNAP/usr/local/lib/python3.6/dist-packages
source-type: git
source: https://github.com/Guake/guake/
source-tag: 3.6.3
plugin: make
- python3-pip
- gettext
- libglib2.0-dev
- gsettings-desktop-schemas
- gir1.2-keybinder-3.0
- gir1.2-notify-0.7
- gir1.2-vte-2.91
- gir1.2-wnck-3.0
- libkeybinder-3.0-0
- libutempter0
#- python3-cairo
#- python3-dbus
#- python3-gi
#- python3-pip

package build correctly. I am able to install it, but of course I can’t run the guake as there are missing runtime dependencies (specifically, python3-gi).

Now, when I uncomment python3-gi in the above file (or any python3-* dependency), the build fails with the error:

make install DESTDIR=/root/parts/guake/install
Traceback (most recent call last):
File “scripts/find-first-site-package.py”, line 4, in
from distutils.sysconfig import get_python_lib
ModuleNotFoundError: No module named ‘distutils.sysconfig’

When I log into the vm shell with

multipass shell snapcraft-guake

I am able to run python3 and successfully import the get_python_lib.

I’m out of idea what can be wrong - it would be awesome if someone could help me understand what am I doing wrong.

I’m building package on Ubuntu 19.10

snapcraft --version
snapcraft, version 3.8

If your making a python snap app I would use the ‘python’ plugin instead of the ‘make’ plugin.

Hi, yes - I probably would do that in any other situation, but build for Guake is driven by make && make install (and make install invokes setup.py).

If there is a way to switch to python plugin and then do make && make install and supress python3 setup.py then I could try that, but that sounds like a hack.

Ok, I tracked down the problem.

So, the error wasn’t showing during the snapcraft build, but during later phase. And in that phase, python3 didn’t have access to distutils. Moving python3-distutils to stage-packages helped. I’m a bit confused by that but that because I don’t know the tool yet!