I have created python application snap and deployed that python application snap on ubuntu 20 LTS.
But i see the logs of snap using below command
snap logs test
gave me an error as below,
“ModuleNotFoundError: No module named ‘xyz’”
So xyz is my custom python module file(xyz.py) and xyz is dependency module of main.py
Can you please tell me how do i integrate or link that xyz module into my python application snap?
Assuming the modules are correctly bundled inside the snap but Python simply cannot find them, set the PYTHONPATH variable pointing to the locations of the modules in the $SNAP subdirectories, you can use the environment stanza to do this.
e.g.
apps:
my-app:
command: myCommand
environment:
PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:${SNAP}/usr/local/lib
You can find your specific path by looking through the mounted snap on the system after installing it (/snap/mysnap/current/) and looking for the relevant module files; by checking the prime folder whilst in the snapcraft build environment, or using unsquashfs on the .snap file and browsing through. All 3 of these approaches are essentially the same thing, varying only on the workflow to do it.
1 Like
thanks James-Carroll, for quick response
Ill try out solution and get back with feedback.
Hi James-Carroll,
I just look xyz module file into prime folder and suggested way, but
Not found any file xyz into directory .
Can you please tell me how to copy that module file into python application snap?
or am i doing wrong?
If your able to, it’d probably be easier to show us the snapcraft.yaml file relevant to your snap so that we can properly inspect it.
The snapcraft build system basically works by pulling some sources, into $SNAPCRAFT_PART_SRC, copying them over into $SNAPCRAFT_PART_BUILD, running the build and copying over the build artifacts into $SNAPCRAFT_PART_INSTALL ; and then applying the prime step at the end. This means you should probably check the parts/myapp/install folder in the snapcraft debug shell too. If it’s not there, check the parts/myapp/build folder instead, if it is there and it isn’t in the install folder, you might need to copy it over manually or adjust your build system. But if it isn’t in the build folder, you’d then check the parts/myapp/src folder, if checking all these 3 folders there isn’t any sign of the module you want, it’s more than likely simply not being included at all and you’d need to work on that.
So tl;dr for now, try and identify if it’s in any of the source/build/install folders in any capacity, if it is we can try fix it so it ends up in the right place at the end, if it isn’t we can try ensure it gets included properly.
Just for the sake of being explicit and to whoever else might stumble upon this in the future, you can access the snapcraft container environment by running snapcraft --shell, which is where these folders would be.