Error building ROS snapcraft when importing python libraries (numpy, matplotlib, etc)

Hi @kyrofa

It works perfectly.

Then, I’ve got this error (As I see, this is a “typicall” error ) with libblas.so.3 and liblapack.so.3. So after reviewing the forum topics, I achieved to this solution that works for me:

parts:
  sick-app-workspace:
    plugin: catkin
    source: .
    build-packages: [python3-pip]
    catkin-packages: [sick_app]
    stage-packages: 
      - libblas-dev 
      - liblapack-dev
      - liblapack3
      - libblas3
    override-build: |
      snapcraftctl build
      set -ex
      for dir in $SNAPCRAFT_PART_INSTALL/usr/lib/*/; do
        (cd $dir;
        if [ -f blas/libblas.so.3.* ]; then
          ln -s blas/libblas.so.3.* libblas.so.3
        fi)
      done
apps:
  ...
  model:
    command: opt/ros/noetic/bin/roslaunch sick_app model_server.launch
    plugs: [network, network-bind]
    extensions: [ros1-noetic]
    environment: 
      LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/blas:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/lapack"

Now, I’m facing the Open3D import error:

Traceback (most recent call last):
  File "/snap/sick-snap-noetic/x1/opt/ros/noetic/lib/sick_app/model_classifier.py", line 17, in <module>
    import open3d as o3d
ModuleNotFoundError: No module named 'open3d'

As you suggested, I made a pull-request to add a python3 rule of open3d. I’ve been waiting the merge since the last week, idk if it will take longer… Is there any way to snap the package with my local rosdep rules? (i.e. from my local python.yaml or from my github personal fork).

Edit: I’m planning to follow this approach (It seems to be similar to the solution you specified here). But at the Snapcraft 4.0 release notes says the core20 is now using the plugins V2, which changes a little bit the situation. After a quick search at plugins/v2 dir, I found this (at line 125):

def get_build_commands(self) -> List[str]:
    return (
        self._get_workspace_activation_commands()
        + [
            "if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ]; then sudo rosdep init; fi",
            "rosdep update --include-eol-distros --rosdistro $ROS_DISTRO",
            "rosdep install --default-yes --ignore-packages-from-source --from-paths $SNAPCRAFT_PART_SRC",
        ]
        + self._get_build_commands()
        + self._get_stage_runtime_dependencies_commands()
    )

I’m not familiar with the [ ] script, but I understand that it verifies the 20-default.list file, and if it isn’t there, it runs rosdep init. I tried editing directly the 20-default.list file to read a local python.yaml file. It works for my local ROS packages, but the snapcraft build failed, I asume it is still executing rosdep init according to this:

+ '[' '!' -f /etc/ros/rosdep/sources.list.d/20-default.list ']'
+ rosdep update --include-eol-distros --rosdistro noetic
reading in sources list data from /etc/ros/rosdep/sources.list.d
Warning: running 'rosdep update' as root is not recommended.
  You should run 'sudo rosdep fix-permissions' and invoke 'rosdep update' again without sudo.
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip distro "ardent" different from requested "noetic"
Skip distro "bouncy" different from requested "noetic"
Skip distro "crystal" different from requested "noetic"
Skip distro "dashing" different from requested "noetic"
Skip distro "eloquent" different from requested "noetic"
Skip distro "foxy" different from requested "noetic"
Skip distro "groovy" different from requested "noetic"
Skip distro "hydro" different from requested "noetic"
Skip distro "indigo" different from requested "noetic"
Skip distro "jade" different from requested "noetic"
Skip distro "kinetic" different from requested "noetic"
Skip distro "lunar" different from requested "noetic"
Skip distro "melodic" different from requested "noetic"
Add distro "noetic"
Skip distro "rolling" different from requested "noetic"
updated cache in /root/.ros/rosdep/sources.cache
+ rosdep install --default-yes --ignore-packages-from-source --from-paths /root/parts/sick-app-workspace/src
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
sick_app: Cannot locate rosdep definition for [python3-open3d-pip]