Python 3.6.7 and GTK3+ Snapcraft


#1

Hi,

My Python app uses Python 3.6.7, but the final Snap ends up with a different version of Python (Python 3.5 I think), which isn’t compatible with my script, because I use some of the newer features in Python 3.6+.

My app uses Python 3.6.7 and GTK3+.
How can I make my Snap use a newer version of Python?

My snapcraft.yaml file is:

name: openresizer # you probably want to 'snapcraft register <name>'
#base: core18 # the base snap is the execution environment for this snap
version: '1.0' # just for humans, typically '1.2+git' or '1.3.2'
summary: Batch image resizer with a GUI # 79 char long summary
description: |
  OpenResizer is an open-source batch image resizing software with a GUI.
  It is designed to be fast and easy-to-use.

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

icon: gui/icon.png

architectures:
  - build-on: [amd64, i386]
    run-on: all

parts:

  main-part:
    # See 'snapcraft plugins'
    plugin: python
    python-version: python3

    stage-packages:
      - python3-pil
      - python3-gi

  wrapper:
    plugin: dump
    source: https://github.com/jrezai/openresizer.git
    source-type: git
    after: [desktop-gtk3]
    prepare: |
      chmod +x bin/openresizer.py

    organize:
      glade_files: bin/glade_files


apps:
  openresizer:
    command: desktop-launch $SNAP/bin/openresizer.py
    plugs: [x11, unity7, pulseaudio, wayland, desktop, desktop-legacy, gsettings, home]

#2

Any ideas on how to use Python 3.6+ in Snapcraft, instead of the default Python 3.5?
This is for a GTK3+ application.


#3

Are you 100% certain that you are running older python3? The core18 base snap ships python 3.6.5, and that is the version of python you are executing under because your $SNAP/bin/openresizer.py has a shebang pointing to /usr/bin/python3 which is a path provided by the base snap.

Two things come to mind here:

  1. You shouldn’t hard-code the path to python - try using env python3 in your shebang or change your command to explicitly use python3: command: desktop-launch python3 $SNAP/bin/openresizer.py
  2. Don’t rely on the base snap providing python at all because it is not guaranteed to be provided by the core18 snap or other base snaps going forward. Though this is mitigated by changing your snap per the first point.

#4

core18 is commented out in that snapcraft.yaml.


#5

Yes, correct. Core18 has been commented out on purpose. I could not find in-depth documentation for using core18 with Python, GTK3, and my app. So I commented out core18 so I could try and get the snap working “the old way” (without core18), because most of the examples that I’ve been seeing for snapcraft are without core18.

When I tried using core18, snapcraft wasn’t able to find my Python files (.py). I’m sure I’m doing something wrong, I’m just not sure what. Should I use the “new way”, with core18, or continue with the yaml I have so far?