Built snap fails on CORE but runs on localhost

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
Best reply by Sgilk

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.

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.

View original
6 replies