/usr/bin/env: ‘python’: No such file or directory —- When I run the snap based on python , It prompts such error. How could I do then?

/usr/bin/env: ‘python’: No such file or directory ---- When I run the snap based on python , It prompts such error. How could I do then? Please help me . thank you .
------------------------------------------------------------------------------------snapcraft.yaml file contnet : below ------
luhx@ubuntu:~/Projects/snap/duplicity/snap$ more snapcraft.yaml
name: aliyunduplicity
version: ‘1.0.0’
summary: aliyun oss duplicity supports full/incremental backup.
description: |
This is duplicity with Aliyun interface.

grade: devel
confinement: devmode

apps:
aliyunduplicity:
command: bin/aliyunduplicity

parts:
aliyunduplicity:
plugin: dump
source: /home/luhx/Downloads/duplicitysource

organize:
bin/aliyunduplicity: bin/aliyunduplicity.py
luhx@ubuntu:~/Projects/snap/duplicity/snap$
------------------------------------------------------------ snapcraft.yaml file content above --------
uhx@ubuntu:~/Projects/snap/duplicity/snap$
luhx@ubuntu:~/Projects/snap/duplicity/snap$ sudo snap install aliyunduplicity_1.0.0_amd64.snap --dangerous --devmode
aliyunduplicity 1.0.0 installed
luhx@ubuntu:~/Projects/snap/duplicity/snap$
luhx@ubuntu:~/Projects/snap/duplicity/snap$ aliyunduplicity
/usr/bin/env: ‘python’: No such file or directory
luhx@ubuntu:~/Projects/snap/duplicity/snap$

Hi,
try like this
python aliyunduplicity

you have to execute it as python script.py, otherwise the default shell will execute it.

Your snap is using devmode confinement, it will see the core snap (i.e. what you see under /snap/core/current) as its root file system. There is no Python 2 interpreter in the core snap, so you get the above error.

There are a few options here:

  1. Use the python Snapcraft part plugin to ship a Python interpreter with your snap.

  2. Switch to classic confinement so you can see the host file system. With this option, your snap might still fail if the host system doesn’t have Python 2 installed though.

As you’re working on packaging a backup tool, classic confinement might be the right choice.

Thank you for your help . I want to copy my “aliyunduplicitylib” to the default python lib directory, so what should I do then ? Where can I run the shell command , maybe there are some more clever method ?
See the picture below, my executable file run based on the “aliyunduplicitylib” .

Maybe the simplest option would be to write a Python distutils setup.py script for your project.

https://docs.python.org/2/distributing/index.html

Snapcraft’s python plugin will know how to build it then, and also make sure the Python interpreter is included in your package (if that’s the option you want to take).

Hi, setup.py script is an official way to solve the problem. If I want to copy the lib in the snapcraft.yaml file , what sould I do ? “copy in the snapcraft.yaml file” is much more flexible in many scenario, sometimes I can testing something ASAP .
Thanks again.

You may need these scriptlets.

parts:
  foo:
    source: .
    plugin: autotools
    install: |
      sed -i 's|/usr/bin|$SNAP/usr/bin|g' my-bin-artifact.sh
      mv my-bin-artifact.sh $SNAPCRAFT_PART_INSTALL/bin/my-bin-build.sh

(Maybe you should cut down the title, thanks!)

Did you see my reply to your essentially identical question here?