# Distributing a ROS2 Foxy system among multiple snaps

**URL:** <https://discourse.openrobotics.org/t/distributing-a-ros2-foxy-system-among-multiple-snaps/27933>\
**Category:** Projects\
**Tags:** ros2, foxy, snapcraft\
**Created:** [October 24, 2022, 11:31pm UTC](https://discourse.openrobotics.org/t/distributing-a-ros2-foxy-system-among-multiple-snaps/27933 "2022-10-24T23:31:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohamedaminhamdad](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/mohamedaminhamdad/32/15038_2.png) [@Mohamedaminhamdad](https://discourse.openrobotics.org/u/Mohamedaminhamdad)\
**Post date:** [October 24, 2022, 11:31pm UTC](https://discourse.openrobotics.org/t/distributing-a-ros2-foxy-system-among-multiple-snaps/27933/1 "2022-10-24T23:31:56Z")

</div>

Hello together, I knew that in ROS1 there is a way to build a snap containing only roscore and build other packages as snaps than on top of the Ros runtime snap. Is this also possible? The Idea is to have a ROS2 foxy as a base snap and than for example an overlay snap "simple talker listener " as a snap which uses the Plug from ROS2 packed in the first snap?

---

<div class="post-metadata">

**Author:** ![Jeremie](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/jeremie/32/1094_2.png) [@Jeremie](https://discourse.openrobotics.org/u/Jeremie)\
**Post date:** [October 26, 2022, 2:51pm UTC](https://discourse.openrobotics.org/t/distributing-a-ros2-foxy-system-among-multiple-snaps/27933/2 "2022-10-26T14:51:48Z")

</div>

Hi @Mohamedaminhamdad,  
I believe you are talking about the ‘content-sharing’ functionality of snaps applied to ROS 2 applications. This feature is not supported for ROS 2 at the moment but good news we are working on it! We’ll make sure to announce it both on the [Ubuntu blog](https://ubuntu.com/blog/topics/robotics) and here on the ROS Discourse so stay tune.

---

<div class="post-metadata">

**Author:** ![Mohamedaminhamdad](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/mohamedaminhamdad/32/15038_2.png) [@Mohamedaminhamdad](https://discourse.openrobotics.org/u/Mohamedaminhamdad)\
**Post date:** [October 26, 2022, 5:22pm UTC](https://discourse.openrobotics.org/t/distributing-a-ros2-foxy-system-among-multiple-snaps/27933/3 "2022-10-26T17:22:07Z")

</div>

Hey Jeremie,  
what I meant is to overlay a workspace (Snap Listener/Talker) on top of a general ROS2 distribution (Snap 2) using plugs and slots. I’ve tried to do so. That’s what I’ve done so far, but still It didn’t work:

I have a snap containing ros2 foxy as a stand-alone ros-base. I’ve done that by building ros2 foxy using the colcon plugin and snapping the install folder, using the following snapcraft file.

```auto
name: ros-base
version: '0.1'
summary: Basic ROS2 listener component
description: |
  Basic ROS2 listener component based on core20

grade: stable
confinement: strict
base: core20
parts:
  dump:
    plugin: colcon
    stage-packages: [
      ros-foxy-ros2launch,
      ros-foxy-ros-core,]
    build-environment:
      - ROS_VERSION: '2'
      - ROS_DISTRO: foxy

slots:
  ros-base:
    interface: content
    content: executables
    read: [/]
    private: false

```

After that I tried to build an overlay snap (simple Hello World talker node) using the following snapcraft file,

```auto
name: overlay
version: '0.1'
summary: Basic ROS2 listener component
description: |
  Basic ROS2 listener component based on core20

grade: stable
confinement: strict
base: core20
parts:
  dump:
    plugin: colcon
    source: src
    build-packages: [make, gcc, g++]
    stage-packages: [ros-foxy-ros2launch, ros-foxy-common-interfaces]
    override-build: |
      snapcraftctl build
    build-environment:
      - ROS_VERSION: '2'
      - ROS_DISTRO: foxy

  wrapper-scripts:
    plugin: dump
    source: ./wrappers/
    organize:
      ./wrapping.wrapper.sh : usr/bin/ros2-custom-ws

apps:
  app4:
    command: usr/bin/ros2-custom-ws

plugs:
  ros-base:
    interface: content
    content: executables
    target: $SNAP/mohamed
    private: false

```

My wrapper file looks like that:

```auto
#!/bin/bash
ROS_BASE=$SNAP/mohamed

export PYTHONPATH=$PYTHONPATH:$ROS_BASE/usr/lib/python3.8/dist-packages:$PYTHONPATH

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/blas
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/lapack
source $SNAP/mohamed/opt/ros/foxy/setup.bash 
$SNAP/opt/ros/snap/lib/py_pubsub/talker 

```

After connecting both snaps slots and plugs I can run the overlay snap using the following command: overlay.app4 Howevere, when doing so, I get the following error:

```auto
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Traceback (most recent call last):
  File "/snap/overlay/x1/opt/ros/snap/lib/py_pubsub/talker", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/ __init__.py", line 3254, in <module>
    def _initialize_master_working_set():
  File "/usr/lib/python3/dist-packages/pkg_resources/ __init__.py", line 3237, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/ __init__.py", line 3266, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/ __init__.py", line 584, in _build_master
    ws.require( __requires__ )
  File "/usr/lib/python3/dist-packages/pkg_resources/ __init__.py", line 901, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/ __init__.py", line 787, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'py-pubsub==0.0.0' distribution was not found and is required by the application

```

My workspace for my overlay ros snap looks like that:

```auto
├── snap
│ └── snapcraft.yaml
├── src
│ └── py_pubsub
│ ├── launch
│ │ └── publisher_launch.py
│ ├── package.xml
│ ├── py_pubsub
│ │ ├── __init__.py
│ │ └── publisher_member_function.py
│ ├── resource
│ │ └── py_pubsub
│ ├── setup.cfg
│ ├── setup.py
│ └── test
│ ├── test_copyright.py
│ ├── test_flake8.py
│ └── test_pep257.py
└── wrappers
    └── wrapping.wrapper.sh

```

---

<div class="post-metadata">

**Author:** ![Mohamedaminhamdad](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/mohamedaminhamdad/32/15038_2.png) [@Mohamedaminhamdad](https://discourse.openrobotics.org/u/Mohamedaminhamdad)\
**Post date:** [October 27, 2022, 7:43am UTC](https://discourse.openrobotics.org/t/distributing-a-ros2-foxy-system-among-multiple-snaps/27933/4 "2022-10-27T07:43:30Z")

</div>

after modifying the wrapper and sourcing the ./local\_setup.bash.

```auto
#!/bin/bash
ROS_BASE=$SNAP/mohamed
export PYTHONPATH=$PYTHONPATH:$ROS_BASE/usr/lib/python3.8/dist-packages
export PYTHONPATH=$PYTHONPATH:$ROS_BASE/usr/lib/python3/dist-packages

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/lib/$TRIPLET
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/usr/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/usr/lib/$TRIPLET
source $SNAP/mohamed/opt/ros/foxy/setup.bash 
source $SNAP/local_setup.bash && $SNAP/py_pubsub/lib/py_pubsub/talker 

```

The distribution py\_pubsub is found. Howevere, now i get the following error:

```auto
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Traceback (most recent call last):
  File "/snap/overlay/x1/py_pubsub/lib/py_pubsub/talker", line 33, in <module>
    sys.exit(load_entry_point('py-pubsub==0.0.0', 'console_scripts', 'talker')())
  File "/snap/overlay/x1/py_pubsub/lib/py_pubsub/talker", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.8/importlib/ __init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/snap/overlay/x1/py_pubsub/lib/python3.8/site-packages/py_pubsub/publisher_member_function.py", line 2, in <module>
    from rclpy.node import Node
  File "/snap/overlay/x1/mohamed/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 42, in <module>
    from rclpy.client import Client
  File "/snap/overlay/x1/mohamed/opt/ros/foxy/lib/python3.8/site-packages/rclpy/client.py", line 22, in <module>
    from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy
  File "/snap/overlay/x1/mohamed/opt/ros/foxy/lib/python3.8/site-packages/rclpy/impl/implementation_singleton.py", line 31, in <module>
    rclpy_implementation = _import('._rclpy')
  File "/snap/overlay/x1/mohamed/opt/ros/foxy/lib/python3.8/site-packages/rclpy/impl/ __init__.py", line 28, in _import
    return importlib.import_module(name, package='rclpy')
  File "/usr/lib/python3.8/importlib/ __init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libspdlog.so.1: cannot open shared object file: No such file or directory
The C extension '/snap/overlay/x1/mohamed/opt/ros/foxy/lib/python3.8/site-packages/rclpy/_rclpy.cpython-38-x86_64-linux-gnu.so' failed to be imported while being present on the system. Please refer to 'https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-even-with-library-present-on-the-system' for possible solutions

```

---

<div class="post-metadata">

**Author:** ![Jeremie](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/jeremie/32/1094_2.png) [@Jeremie](https://discourse.openrobotics.org/u/Jeremie)\
**Post date:** [October 31, 2022, 10:53pm UTC](https://discourse.openrobotics.org/t/distributing-a-ros2-foxy-system-among-multiple-snaps/27933/5 "2022-10-31T22:53:55Z")

</div>

Hi @Mohamedaminhamdad,  
The ROS Discourse isn’t really the place to address help queries. Since you’ve also open a thread on the [Snapcraft forum](https://forum.snapcraft.io/t/snapcraft-ros2) I will take the discussion over there.
