Noob assistance on new python snap

I would really appreciate some help here. It’s probably a fundamental error, but I just can’t see it at the moment!

I’m trying to make a snap of this Metamorphose2 renamer:



(it installs on Ubuntu18.04, but not on 20.04, so I thought a snap would be a good idea)

There’s no compile necessary, there’s just a make file that copies files to their targets, and some dependencies. Should be easy, I thought!

Here’s my experimental snap.yaml:

name: my-snap # you probably want to 'snapcraft register <name>'
base: core18 # the base snap is the execution environment for this snap
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.

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


apps:
  metamorphose2:
    command: python $SNAP/usr/share/metamorphose2/metamorphose2.py

parts:
  my-part:
    plugin: make
    source: metamorphose2-master
    stage-packages:
    - python-wxgtk3.0
    - python-pil
    - python-mutagen
    - python-exif
    - python

I changed the command because it was looking for the script in the wrong place. For some reason it changes any occurrence of ‘/usr’ to ‘/root/parts/my-part/install/usr’.

Now it can’t find a python dependency:

Traceback (most recent call last):
  File "/snap/my-snap/x1/usr/share/metamorphose2/metamorphose2.py", line 188, in <module>
    main(wx_version, cli_options)
  File "/snap/my-snap/x1/usr/share/metamorphose2/metamorphose2.py", line 173, in main
    import MainWindow
  File "/snap/my-snap/x1/usr/share/metamorphose2/MainWindow/__init__.py", line 38, in <module>
    import sorting
  File "/snap/my-snap/x1/usr/share/metamorphose2/sorting/__init__.py", line 25, in <module>
    from exif import EXIF
ImportError: No module named exif

Although it references it in the snapcraft output:

Get:1 python-exif_2.1.2-1_all.deb [27.7 kB]                                                                                                  
Fetched 27.7 kB in 0s (0 B/s)   

I’m afraid my understanding is still very limited, but any pointers would be much appreciated!
Thanks.

I haven’t snapped python programs so far, but maybe using the python plugin can help you setting up the required environment mappings? At least I don’t see anything in my-part that necessitates use of the make plugin :slightly_smiling_face:

Hi, Many thanks for replying. I have tried the python plugin, without success. My understanding is that it expects the type of “setup.py” installation (which this isn’t). It “should” just use the makefile to copy the executables to the target. But I’ve clearly got something wrong!

The python plugin is essentially a driver for pip, but also sets up python for proper use within a SNAP, when using the make plugin this environment is not setup (environment setup is slowly being moved to Snapcraft extensions as time and backwards compatibility permit).

If your goal is to stay within the realms of strict/devmode, then simply adding PYTHONPATH through the environment keyword to point to the dist-packages should be enough… from memory that path I believe would be something like $SNAP/usr/lib/python2.7/dist-packages

1 Like

Thank you for the hints. This would certainly make sense, and there is obviously more going on here than I understand!

I will do some more reading on the environment and PYTHONPATH, though I don’t at the moment know the significance of “staying within the realms of strict/devmode”.