Bundling OpenCV and/or Numpy in ROS snap for Ubuntu Core

Hi,

I’ve been trying without luck to package a ROS system as a snap. I’ve modeled the process after Kyrofa’s guide, but my system depends on components like OpenCV and Numpy, which seem to go beyond the scope of the guide. I’m aware of the need to include the install() directives on CMakeLists.txt, as well as declaring the <run_depend>s on package.xml.

After installing the snap and running the command (a launch file), the nodes that depend on numpy and/or opencv crash, with the following messages:

  File "/snap/*****/x5/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 14, in <module>
    from . import multiarray
ImportError: libblas.so.3: cannot open shared object file: No such file or directory

and

  File "/snap/dispatcher-ui/x5/opt/ros/kinetic/lib/*******/*********", line 8, in <module>
    import cv2
ImportError: numpy.core.multiarray failed to import

The latest version of my snapcraft.yaml file looks like this (asterisks added for this post). I attempted to add a bunch of stage-packages, but nothing changed.

name: ******** # you probably want to 'snapcraft register <name>'
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: *****************************
description: |
  ***************

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

parts:
  prototype-workspace:
    plugin: catkin
    rosdistro: kinetic
    catkin-packages: [**package1**,**package2**,**package3**]
    stage-packages:
       - python-numpy
       - python-dev
       - libblas3
       - liblapack3
       - libopenblas-dev
       - liblapack-dev    

apps:
  system:
    command: roslaunch ****some package*****  ***some launch file******.launch --screen
    plugs: [network, network-bind]

package.xml

 <build_depend>message_generation</build_depend> 
  <buildtool_depend>catkin</buildtool_depend> 
  <run_depend>message_runtime</run_depend> 
  <build_depend>geometry_msgs</build_depend>
  <build_depend>move_base_msgs</build_depend>
  <build_depend>actionlib</build_depend>
  <build_depend>actionlib_msgs</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>nav_msgs</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>tf</build_depend>
  <build_depend>roscpp</build_depend>

  <run_depend>geometry_msgs</run_depend>
  <run_depend>nav_msgs</run_depend>
  <run_depend>std_msgs</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>tf</run_depend>
  <run_depend>move_base_msgs</run_depend>
  <run_depend>actionlib</run_depend>
  <run_depend>actionlib_msgs</run_depend>
  <run_depend>message_generation</run_depend>
  <run_depend>roscpp</run_depend>
  <run_depend>python-opencv</run_depend>
  <run_depend>python-numpy</run_depend>

My CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8.3)
project(my_node)


find_package(catkin REQUIRED COMPONENTS
  roscpp
  geometry_msgs
  nav_msgs
  rospy
  std_msgs
  message_generation
  actionlib
  actionlib_msgs
  move_base_msgs
)

find_package(OpenCV REQUIRED COMPONENTS)


generate_messages(
   DEPENDENCIES
   std_msgs
   geometry_msgs
   actionlib_msgs
)

catkin_package(
  CATKIN_DEPENDS actionlib_msgs
)


include_directories(
  ${catkin_INCLUDE_DIRS}
)


add_executable(some_cpp_node some_cpp_node.cpp)
target_link_libraries(relay_nonzero ${catkin_LIBRARIES})


install(PROGRAMS some_script.py another_script.py...etc
    DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY launch/
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

Any guidance would be greatly appreciated!

Nick

I had this same issue a while ago, and still do to some degree. The thread I posted was here: Update-alternatives not placed in snap

A workable solution is in this post. The root issue still exists, but you’ll be able to get it running. The downside is even when I made that post the behavior of libblas had changed so you may need to update your snapcraft.yaml when libblas updates.

Thank you, I appreciate the insight. I’ll give the patch a try.