Aliyundup snap based on python

I have installed the aliyundup snap successfully. But when I run it , it prompts error “ImportError: No module named lockfile”. In fact , the python module “lockfile” is ok in the console python enviroment. You can see it in the picture.
Thank you.
------------------------------------------snapcraft.yaml file content is below --------------------------------------------------

name: aliyundup
version: '1.0.0'
summary: aliyun oss duplicity supports full/incremental backup. 
description: |
  This is duplicity with Aliyun interface. 

grade: devel
confinement: classic 

apps:
  aliyundup:
    command: bin/aliyundup

parts:
  aliyundup:
    plugin: python2
    source: /home/luhx/Projects/aliyundupsnap

a snap runs in its own environment so what you get when running your app non-snapped in console is not really relevant …

to have your snap ship the lockfile module, just add a stage-packages line to your part and list the python-lockfile package there …

one sidenote:
you seem to be opening one (or actually multiple) topic for each question you have about this snap, this makes the frontpage of the forum pretty unreadable, would you mind just renaming this topic to something like “aliyundup snap” (like others do) and just ask your questions in this single thread ? this makes it also a lot easier for us to answer.

Thank you for your advice. I add the stage-packages, but still get error.

luhx@ubuntu:~/Projects/snap/dupsetupsnap/snap$ sudo snapcraft
DEPRECATED: The ‘python2’ plugin’s functionality has been replaced by the ‘python’ plugin, and it will soon be removed.
Preparing to pull aliyundup
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Hit http://us.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 0s (0 B/s)
Error downloading stage packages for part ‘aliyundup’: The package ‘lockfile’ was not found.

name: aliyundup
version: '1.0.0'
summary: aliyun oss duplicity supports full/incremental backup. 
description: |
  This is duplicity with Aliyun interface. 

grade: devel
confinement: classic 

apps:
  aliyundup:
    command: bin/aliyundup

parts:
  aliyundup:
    plugin: python2
    source: /home/luhx/Projects/aliyundupsnap
    stage-packages:
      - lockfile

that should be “python-lockfile”

(also regard the warning and use “plugin: python” not python2)

lockfile really works according to your advice. but there is another module error. The oss2 module is not python build-in module, it’s our aliyun module , we can “pip install oss2” install it.
Please help me , thank you .

name: aliyunduplicity
version: '1.0.0'
summary: aliyun oss duplicity supports full/incremental backup. 
description: |
  This is duplicity with Aliyun OSS interface. 

grade: devel
confinement: classic 

apps:
  aliyundup:
    command: bin/aliyunduplicity

parts:
  aliyundup:
    plugin: python
    python-version: python2
    source: /home/luhx/Projects/duplicitysnap
    stage-packages:
      - python-lockfile
      - python-oss2

i have never used pip in snaps, perhaps @sergiusens or @kyrofa have a hint ?

(python-oss2 is definitely wrong there though, since no such deb package exists in the archive (stage-packages describes deb packages to be installed inside your snap, only packages existing in the ubuntu archive will work for this))

In snapcraft.yaml, is there any way to copy my own source library to a snap directory ? Could you give me an example? that way is much more flexible for many scenarios . and please make it clear what the root( or relative root ) is. this maybe a workaround for oss2.

technically there are no limits when using snapcraft (you could use the make plugin, add a Makefile and have everything built from source and copied around to your liking etc) snapcraft is extremely flexible in all directions, so there is surely a way to copy your own lib …

when a snap is executed it runs inside the core snap but with a bunch of bits bind mounted into it from the host system, all binary executions are guarded by seccomp monitoring and cgroup namespaces, all file access is guarded by apparmor … if your snap needs to access anything that is not allowed by the default setup you can use snap interfaces to drop restrictions of the apparmor/seccomp/namespace limits.

if you want to enter the snap environment you can use “snap run --shell yoursnap-app” to enter and inspect it.

Thank you very much. And hope there is a much more perfict solution for those modules such as “pip install oss2”.

Please give me some advices. Thanks.

you picked “confinement: classic” in your snapcraft.yaml … that means “drop all security”.

snaps that drop security need to be reviewed manually by a store admin for every upload …

How long about the review ? if not classic mode , what else could I do? In devmode I cannot use the python in Ubuntu, and I don’t have a good example how to use the devmode gracefully. Do you have any good advice? Thanks a lot.

The oss2 module problem is solved . thanks all.

what are the errors you get when using “confinement: devmode”, installing your snap locally with the --dangerous and --devmode options and run it ? lets go through them (there are plenty confined python snaps in the store that work just fine, confinement should only get in your way when accessing any hardware (for which we have interfaces you can enable))

I want to add “apt install ***” into the snapcraft.yaml file, and want to run it before the “plugin: python” part, how can I make it? thank you.

you want the “build-packages” directive … that installs packages for a part before it runs the part …

THANKS. You are genius. …

if I want to “apt install aaaa”, but somtimes the “aaaa” has been installed in some machines of customers. andI do not want to install “aaaa” in this scenario, how could I do in the.snapcraft.yaml file? thanks.

do you mean for building the snap ?
(if it is for running the snap … it is very likely that aaa is not contained in the core snap, so you should simply ship it with your snap in stage-packages)

aaaa is the dependency of the snap. I have to install aaaa before the snap.