Failed to copy: can't figure out file structures

Beginner question here: I’m trying to deploy a simple python application. My files are organized like this:

.
├── camstream.py
├── product-setup
├── snap
│   └── snapcraft.yaml
├── static
│   └── product-logo-color.jpg
└── templates
    └── index.html

and my snapcraft file looks like this:

parts:
  product-setup:
    plugin: python
    python-packages: [flask, numpy, opencv-contrib-python, imutils]

    build-environment:
      - PYTHONPATH: "$SNAPCRAFT_PART_INSTALL/usr/lib/python3/dist-packages"

    stage-packages:
      - python3-wheel

    filesets:
      product-setup:
      - templates/*
      - static/*

    stage:
      - $product-setup
      - camstream.py

    prime:
     - $product-setup
     - camstream.py

and I keep getting an error

Failed to copy '/root/parts/product-setup/install/camstream.py': no such file or directory.
Check the path and try again.

I thought that the “prime” section, with the file name, would put it in the correct place. Is this a misunderstanding?

Hi,

The python plugin to snapcraft requires your Python project to be set up with a setup.py file to handle installing the files in their correct locations on the system or a staging-area (the staging area being a snapcraft-specific location). The setup.py should indicate what your app’s entry point is along with all the files that should be installed.

With a proper setup.py your app and all files will be installed into $SNAPCRAFT_PART_INSTALL and then from there will make their way into the snap package. Without a setup.py snapcraft has no way of knowing how to install your app. You could try to work around the requirement by utilising the dump plugin instead but this is not well-suited to python projects.

1 Like

Thank you! Where would I have known that? It’s mentioned that you can use a setup.py in https://snapcraft.io/docs/python-plugin.

Thanks for pointing out the error in the documentation. I’ve rewritten the first sentence to hopefully help others coming along later. I know it doesn’t help your situation of the docs misleading you, but hopefully you can take a bit of solace that you’ve improved the docs for everyone.

1 Like