Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Built snap fails on CORE but runs on localhost

Built snap fails on CORE but runs on localhost

K-Zanaty
Established Member

Hello everyone,

we want to build our own first SNAP. However, we are currently facing issues.

When I execute the code inside the suitable environment, it is working OK. When I build the snap and install it on a virtual ctrlX CORE V2.4, I receive the following information via ssh:

 

2024-06-13T16:41:33Z systemd[1]: Started Service for snap application lincap.webserver.
2024-06-13T16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 1: from: not found
2024-06-13T16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 2: from: not found
2024-06-13T16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 3: from: not found
: not found16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 4:
: not found16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 5:
2024-06-13T16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 10: Syntax error: "(" unexpected (expecting "then")
2024-06-13T16:41:33Z systemd[1]: snap.lincap.webserver.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
2024-06-13T16:41:33Z systemd[1]: snap.lincap.webserver.service: Failed with result 'exit-code'.
2024-06-13T16:41:42Z systemd[1]: Stopped Service for snap application lincap.webserver.

In these lines 1-3 I try to import from a local package

from src.xmlrpc_server import XmlRpcServer
from src.servos import Servo
from src.control_functions import  ControlFunctions

Although I included the packages into the setup.py, they are not recognized. Maybe someone has a hint, thanks a lot!

from setuptools import setup

setup(
    name='appname',
    version='1.1.0',
    description='description',
    author='me',
    packages=['app', 'appdata', 'motion.core.fbtypes', 'robot.core.fbtypes', 'src', 'src.rtde'],
#src.rtde is used by python script inside the folder src
    install_requires=['flask', 'ctrlx-datalayer', 'ctrlx-fbs', 'pyopenssl'],
    package_data={},
    scripts=['main.py', 'datalayerProvider.py', 'fbsFunction.py'],
    license='Copyright (c) 2024'
)

 

Here is the folder structure:

 

my_project/
├── snap/
│   └── snapcraft.yaml
├── main.py
├── src/
│   ├── __init__.py
│   ├── module1.py
│   ├── module2.py
│   ├── rtde/
│   │   ├── __init__.py
│   │   ├── submodule1.py
│   │   └── submodule2.py
├── app/
│   ├── __init__.py
├── appdata/
│   ├── __init__.py
├── motion/
│   ├── core/
│   │   ├── __init__.py
│   │   ├── fbtypes.py
├── robot/
│   ├── core/
│   │   ├── __init__.py
│   │   ├── fbtypes.py
└── setup.py
6 REPLIES 6

Sgilk
Frequent Contributor

Hi @K-Zanaty ,

Can you please provide your snapcraft.yaml? It seems these packages are not being provided in the built application.

Are you including the src/ directory in the snapcraft build? Since these are local modules, you should be able to use the python plugin with the source attribute set to "." as below. So long as these packages are in your setup.py, like you've shown, they should be available in the built snap.

parts:
  provider:
    plugin: python
    source: .
    stage-packages:
      - libzmq5
      - ctrlx-datalayer
    python-packages:  
      - ./whl/pylogix-1.0.0-py2.py3-none-any.whl
      - ./whl/pycomm3-1.2.14-py3-none-any.whl 

 

K-Zanaty
Established Member

Sure, please find below my file content:

 

name: name
version: 1.0.0
summary: summary
title: title
description: |
  description
base: core22
confinement: strict
grade: stable

apps:
  webserver:
    command: bin/main.py
    plugs:
      - network
      - network-bind
      - datalayer
      - active-solution
    slots:
      - package-assets
      - package-run
    daemon: simple
    restart-condition: always
    passthrough:   
      restart-delay: 10s

parts:
  webserver:
    plugin: python
    source: .
    stage-packages:
      - libzmq5
      - ctrlx-datalayer
  
  bfbs:
    plugin: dump
    source: ./bfbs
    organize:
      '*': bfbs/

  mddb:
    plugin: dump
    source: ./mddb
    organize:
      '*': mddb/
  
  templates:
    plugin: dump
    source: ./templates
    organize:
      '*': templates/

  static:
    plugin: dump
    source: ./static
    organize:
      '*': static/

  configs:
    source: ./configs
    plugin: dump
    organize:
      'package-assets/*': package-assets/${SNAPCRAFT_PROJECT_NAME}/

slots:
  package-assets:
    interface: content
    content: package-assets
    source:
      read:
        - $SNAP/package-assets/${SNAPCRAFT_PROJECT_NAME}
  package-run:
    interface: content
    content: package-run
    source:
      write:
        - $SNAP_DATA/package-run/${SNAPCRAFT_PROJECT_NAME}

plugs:
  datalayer:
    interface: content
    content: datalayer
    target: $SNAP_DATA/.datalayer

  active-solution:
    interface: content
    content: solutions
    target: $SNAP_COMMON/solutions

project details in name and description are changed 

Sgilk
Frequent Contributor

When you snap the app, is this portion of your source directory available in the snapcraft /prime folder?

├── src/
│   ├── __init__.py
│   ├── module1.py
│   ├── module2.py
│   ├── rtde/
│   │   ├── __init__.py
│   │   ├── submodule1.py
│   │   └── submodule2.py

K-Zanaty
Established Member

Hi,

no, I could not see it.

Also, there is an issue in finding additional, non script, files the scripts try to read and parse (e.g. in folder "config/file.xml"). After some debugging, I can see them in the prime folder and also in the snap-extract (using <unsquashfs -d ... >) but the snap keeps reporting that it cannot find the files.

I am assuming that I'm still very unsure about the correct configuration and at which place which file has to live to work as a snap..

Sgilk
Frequent Contributor

Sorry, I should have specified better. It should be in the prime/lib(64)/python3.8/site-packages directories. Here is an example using modules from the /app source directory.

Sgilk_0-1718377047974.png

There are many different ways to build snaps, so there are many "correct" configurations. It's often a matter of preference. Snapcraft has pretty good documentation and debug support but is definitely complex.

@K-Zanaty You could have a look to our web-based training "ctrlX AUTOMATION SDK II" and see if it can help you getting more familiar with building apps.

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist