Python plugin on core20 can't find ensurepip

I’m trying to port fakecam to core20. The problem is no matter what I try to change the python plugin refuses to set up the venv with the following output:

Building fakecam 
+ snapcraftctl build
+ python3 -m venv /root/parts/fakecam/install
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/root/parts/fakecam/install/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

Failed to build 'fakecam'.

Recommended resolution:
Check the build logs and ensure the part's configuration and sources are correct.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.

My core20 branch is at: https://github.com/diddlesnaps/fakecam/tree/core20

I’ve tried adding python-venv in the stage-packages, in the build-packages, and in a separate part’s stage-packages that fakecam part depends upon. None of these things worked. I’ve also tried setting PYTHONPATH in build-environment to include a location with ensurepip.

Agreed to discuss this as part of the Snapcraft Clinic

1 Like

While it is great that you discussed it with @lucyllewy in the clinic to help with his specific problem, has there been a written down document of this clinic discussion so that the others of us running into this problem have at least a remote idea what to do about it ?

i have not managed to port any of the 20 or so snaps i have that use the python plugin successfully to core20 yet and the one that i’m just developing from scratch for a customer fails exactly in the above way … but all i can find about this issue is this post with no helpful resolution at all …

(sorry for the rant but it is massively annoying that such solutions happen in 1x1 video calls without being documented in any way, this is like having to scroll through a youtube video to find the one cmdline you are looking for instead of being able to grep through some website text (which seems to be common among the younger generation) … /me shakes his cane)

1 Like

IIRC, I think the problem here was a bug with combination of the python core20 plugin and gnome 3.38. I think it ended up using the python3 shipped with gnome platform sdk snap instead of the host’s. But I could be wrong. I think @sergiusens followed up with the desktop team…

well, thanks for answering … i finally solved my problem as well in the end

it could somehow be made clearer (probably by some bold emphasis in the plugin doc or so) that you can not combine python-packages: with any deb based python packages added to stage-packages:

creating an extra part that pulled in the stage-packages separately (i only needed a single pip based package that simply isnt available in the archive) and mangling PYTHONPATH in an environment stanza finally made it work … the snapcraft.yaml seems to feel more bloated and complex with each of these changes though …

and i also wonder if we could not detect that there is a stage package with python-* in its name and warn the user that things will break in her face …

The gnome-3-38 extension adds PYTHONPATH to, and augments PATH in, the build-environment which breaks the python plugin. The fix for me was to override the environment to make python be found from the host first, and nuke the PYTHONPATH:

parts:
  my-part:
    plugin: python
    ...
    build-environment:
      - PATH: /usr/bin:$PATH
      - PYTHONPATH: ''
1 Like

The expected fix is to make the GNOME extension and the python plugin work well together.