When I run my snap, it prompts file "not found", in fact it does exist there

When I run my snap, it prompts file “not found”, in fact it does exist there. Please give me some help . Thank you .

Check the shebang, I bet it’s pointing to a python that doesn’t exist. I suggest making sure your shebangs look like #!/usr/bin/env python (or python3, whatever it is).

Thank you , But when I change back to “#!/usr/bin/env python”, it prompts “/usr/bin/env: ‘python2’ : No such file or directory” , in fact it works well in the console .

  1. Did you try just #!/usr/bin/env python? (no 2)
  2. Is python actually in the snap? /snap/aliyoduplicity/current/usr/bin/python

Being able to see your snapcraft.yaml would be helpful, here.

1 Like

Kyrofa, thank you for your help . that’s my snapcraft.yaml . I did not know " /snap/aliyoduplicity/current/usr/bin/python" is a condition, how to make it ?
------------------------------------------------------------------------------------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$

How can I make python actually in the snap?

You need to use Snapcraft’s python plugin. Just using dump doesn’t ask python to pull in anything at all: it literally dumps the content of the source directory into the snap, which in this case is just that python file I expect (i.e. not python itself).

Assuming you’re using python2 from the previous posts, try something like this for your parts:

parts:
  aliyunduplicity:
    plugin: python
    python-version: python2
    # The source should be contained within the same dir that contains the
    # snap dir (or nested below that) and be relative rather than absolute.
    source: duplicitysource
    # Assuming you don't have a setup.py to install stuff, you can do it this way:
    install: |
      mkdir -p $SNAPCRAFT_PART_INSTALL/bin
      cp bin/aliyunduplicity $SNAPCRAFT_PART_INSTALL/bin/

I have tried the “install” script. But the $SNAPCRAFT_PART_INSTALL is empty. and what the absolute path of “ bin/aliyunduplicity” and “$SNAPCRAFT_PART_INSTALL/bin/” ? The root of the “bin/aliyunduplicity” is “source: duplicitysource” , right? what is the '$SNAPCRAFT_PART_INSTALL" ?

Hi, in the “parts: install” of the snapcraft.yaml file , I want to copy my own python lib “duplicity” to /snap/aliyunduplicity/current/lib/python2.7/site-packages, and the python lib “duplicity” is in the subfolder of “source:duplicitysource” (duplicitysource/duplicity) . what should I do in the snapcraft.yaml file ?

I find snapcraft will copy the source files (the same directory as snapcraft.yaml) to the build direcotry of the part automaticly , is that right ? that’s useful but I don’t know the reason and who tiggers it. But I cannot do the copy in the “part: install” because it cannot visit the source files …

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

grade: stable #stable #devel
confinement: devmode 

apps:
  aliyunduplicity:
    command: bin/aliyunduplicity

parts:
  aliyunduplicity:
    plugin: python
    python-version: python2
    stage-packages:
      - librsync-dev
      - python-lockfile
      - python-crcmod
      - python-requests
    python-packages:
      - oss2
    install: |
      echo "++++++++++++++++++++++++++++++++++++++++"
      cp aliyunsource/bin/aliyunduplicity $SNAPCRAFT_PART_INSTALL/bin/
      cp -r aliyunsource/duplicity $SNAPCRAFT_PART_INSTALL/lib/python2.7/site-packages/
      echo "----------------------------------------"

When the install shell snippet runs you are in the ./parts/partname/build/ directory… try using relative paths like:

mkdir -p $SNAPCRAFT_PART_INSTALL/bin
cp …/…/…/bin/aliyunduplicity $SNAPCRAFT_PART_INSTALL/bin/

I find snapcraft will copy the source files (the same directory as snapcraft.yaml) to the build direcotry of the part automaticly , is that right ? that’s useful but I don’t know the reason and who tiggers it. Maybe the “plugin: python” will do the copy action. I want to make it clear. Please give some help.

you can see the snapcraft.yaml content below, in the install shell snippet I only copy the file&folder from the “bulid” root directory to the “install” directory . But these file&folder have already been put into the “parts/aliyunduplicity/build” directory.

apps:
  aliyunduplicity:
    command: bin/aliyunduplicity

parts:
  aliyunduplicity:
    plugin: python
    python-version: python2
    stage-packages:
      - librsync-dev
      - python-lockfile
      - python-crcmod
      - python-requests
    python-packages:
      - oss2
    install: |
      echo "++++++++++++++++++++++++++++++++++++++++"
      cp aliyunsource/bin/aliyunduplicity $SNAPCRAFT_PART_INSTALL/bin/
      cp -r aliyunsource/duplicity $SNAPCRAFT_PART_INSTALL/lib/python2.7/site-packages/
      echo "----------------------------------------"