Need help snapping a python app

Hi,

I’m trying to snap my own local python package/app and run into some issues. Sample app is here: GitHub - juergh/testsnap

It’s a very simple classic snap that contains a python app that calls a system command (dput - another python program). The current state is that the execution of dput fails because it seems confused (see below) by PYTHONPATH which I had to set in snapcraft.yaml.

Questions/issues:

  1. Why do I have to manually stage the python interpreter? Shouldn’t snapcraft figure out by itself that it’s required?
  2. enable-patchelf seems necessary to prevent lint warnings. Do I really need this or am I doing something wrong?
  3. I need to set PYTHONPATH otherwise I’m getting the below, but PYTHONPATH breaks dput. It feels wrong to have to specify PYTHONPATH
Traceback (most recent call last):
  File "/snap/testapp/x3/bin/testapp", line 5, in <module>
    from testapp.testapp import main
ModuleNotFoundError: No module named 'testapp'

Current output:

$ /snap/bin/testapp 
Calling dput...
Traceback (most recent call last):
  File "/usr/bin/dput", line 33, in <module>
    sys.exit(load_entry_point('dput==1.1.3+ubuntu3', 'console_scripts', 'execute-dput')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/dput", line 25, in importlib_load_entry_point
    return next(matches).load()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/metadata/__init__.py", line 205, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/usr/share/dput/dput/dput.py", line 34, in <module>
    from .helper import dputhelper
  File "/usr/share/dput/dput/helper/dputhelper.py", line 17, in <module>
    import pkg_resources
  File "/snap/testapp/x6/lib/python3.10/site-packages/pkg_resources/__init__.py", line 2172, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?

Any help is greatly appreciated. Thanks!

Add the path of test snap module to PYTHONPATH environment variable.

If the linter says so it is usually correct. The classic confinement snap runtime is different from the one in strict confinement so special care is needed.

1 Like

If the linter says so it is usually correct. The classic confinement snap runtime is different from the one in strict confinement so special care is needed.

Thanks for that clarification.

Add the path of test snap module to PYTHONPATH environment variable.

Which path is that? I’m not sure how this would unconfuse dput.

1 Like

Has the snap been published? Or somewhere available to look into?

The snap is here: Index of /~juergh/snap

This seems to be an unfortunate interaction of PYTHONPATH with the host’s Python version. 3.11 on the host works, 3.12 doesn’t. Googling reveals that Python 3.12 got rid of […the long-deprecated pkgutil.ImpImporter class…]. https://stackoverflow.com/questions/77364550/attributeerror-module-pkgutil-has-no-attribute-impimporter-did-you-mean

Which to me seems I need to get rid of PYTHONPATH somehow.

For the record, switching to base: core24 fixed the problem.

1 Like