Hi everyone.
Currently I’m working on building a ROS application on a snap package. Previously, I had an installation rule problem with C++ executables (here).
Now, I have a model_server.launch
file that launches two nodes in python, like:
<launch> <node pkg="sick_app" name="server_classifier_A" type="model_classifier.py" output="screen" > </node> <node pkg="sick_app" name="img_saver_A" type="image_generator.py" output="screen"> </node> </launch>
Now, I’m having a problem with the python part. After building the snap (snapcraft
command) and install it, the following errors appears when I try to run the snap app. For the model_classifier.py
:
Traceback (most recent call last): File "/snap/sick-snap-test/x1/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 16, in <module> from . import multiarray ImportError: cannot import name 'multiarray' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/sick_app/model_classifier.py", line 2, in <module> import numpy as np File "/snap/sick-snap-test/x1/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 142, in <module> from . import add_newdocs File "/snap/sick-snap-test/x1/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module> from numpy.lib import add_newdoc File "/snap/sick-snap-test/x1/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module> from .type_check import * File "/snap/sick-snap-test/x1/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module> import numpy.core.numeric as _nx File "/snap/sick-snap-test/x1/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 26, in <module> raise ImportError(msg) ImportError: Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try `git clean -xdf` (removes all files not under version control). Otherwise reinstall numpy. Original error was: cannot import name 'multiarray' Traceback (most recent call last): File "/snap/sick-snap-test/x1/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 16, in <module> from . import multiarray ImportError: cannot import name 'multiarray'
And for the image_generator.py
:
Traceback (most recent call last): File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/sick_app/image_generator.py", line 2, in <module> import rospy Traceback (most recent call last): File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 47, in <module> File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/python2.7/dist-packages/std_msgs/msg/__init__.py", line 1, in <module> from ._Bool import * File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/python2.7/dist-packages/std_msgs/msg/_Bool.py", line 6, in <module> import genpy File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/python2.7/dist-packages/genpy/__init__.py", line 34, in <module> from . message import Message, SerializationError, DeserializationError, MessageException, struct_I import genpy File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/python2.7/dist-packages/genpy/message.py", line 46, in <module> import genmsg File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/python2.7/dist-packages/genmsg/__init__.py", line 33, in <module> File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/python2.7/dist-packages/genpy/message.py", line 46, in <module> import genmsg from . base import MSG_DIR, SRV_DIR, EXT_MSG, EXT_SRV, SEP, log, plog, InvalidMsgSpec, log_verbose, MsgGenerationException File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/python2.7/dist-packages/genmsg/base.py", line 52, in <module> File "/snap/sick-snap-test/x1/opt/ros/melodic/lib/python2.7/dist-packages/genmsg/__init__.py", line 33, in <module> import inspect, pprint File "/snap/sick-snap-test/x1/usr/lib/python3.6/inspect.py", line 41, in <module> import linecache File "/snap/sick-snap-test/x1/usr/lib/python3.6/linecache.py", line 11, in <module> import tokenize File "/snap/sick-snap-test/x1/usr/lib/python3.6/tokenize.py", line 33, in <module> import re File "/snap/sick-snap-test/x1/usr/lib/python3.6/re.py", line 142, in <module> class RegexFlag(enum.IntFlag): AttributeError: module 'enum' has no attribute 'IntFlag'
I’m importing the following libraries in those scripts. For model_classifier.py
:
#!/usr/bin/env python3 import numpy as np import sys import os import csv import getpass from sick_app.srv import * import math import rospy import time import datetime from time import strptime from scipy.stats import zscore from sick_app.msg import Img import open3d as o3d import matplotlib.pyplot as plt import open3d as o3d
and for image_generator.py
:
#!/usr/bin/env python3 import rospy import os from sick_app.msg import Img import math import time import sys import numpy as np import matplotlib matplotlib.use('Agg') from matplotlib import pyplot as plt import matplotlib.cm as cm from PIL import Image, ImageFilter
As I found here, I added the python plugin to my snapcraft.yaml
file:
parts: sick-app-workspace: # See 'snapcraft plugins' plugin: catkin source: . catkin-packages: [sick_app] stage-packages: - python3 - python3-pil - python3-tk - libblas-dev pythonpackages: plugin: python python-version: python3 python-packages: - numpy - matplotlib - Pillow - scipy - open3d
Also (according to this) I added the exec_depend
lines at the package.xml
file:
<?xml version="1.0"?> <package format="2"> <name>sick_app</name> <version>0.0.0</version> <license>TODO</license> <buildtool_depend>catkin</buildtool_depend> <build_depend>roscpp</build_depend> <build_depend>rospy</build_depend> <build_depend>std_msgs</build_depend> <build_depend>tf</build_depend> <build_depend>eigen</build_depend> <build_depend>message_generation</build_depend> <build_depend>sick_scan</build_depend> <build_depend>roslaunch</build_depend> <build_export_depend>roscpp</build_export_depend> <build_export_depend>rospy</build_export_depend> <build_export_depend>std_msgs</build_export_depend> <build_export_depend>message_runtime</build_export_depend> <exec_depend>roscpp</exec_depend> <exec_depend>rospy</exec_depend> <exec_depend>std_msgs</exec_depend> <exec_depend>tf</exec_depend> <exec_depend>eigen</exec_depend> <exec_depend>message_runtime</exec_depend> <exec_depend>sick_scan</exec_depend> <exec_depend>python3-matplotlib</exec_depend> <exec_depend>python3-numpy</exec_depend> <exec_depend>python3-pil</exec_depend> <exec_depend>python3-scipy</exec_depend> <!-- The export tag contains other, unspecified, tags --> <export> <!-- Other tools can request additional information be placed here --> </export> </package>
and my CMakeLists.txt
looks like:
cmake_minimum_required(VERSION 3.0.2) project(sick_app) add_compile_options(-std=c++11) find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs tf genmsg sick_scan roslaunch ) find_package(Eigen3 REQUIRED) roslaunch_add_file_check(launch) add_service_files( FILES model.srv ) add_message_files( FILES Img.msg ) generate_messages( DEPENDENCIES std_msgs sick_app ) catkin_package( CATKIN_DEPENDS message_runtime std_msgs sick_scan ) include_directories(src ${EIGEN3_INCLUDE_DIRS}) include_directories(include ${catkin_INCLUDE_DIRS}) add_executable(node_filter src/node_filter.cpp src/filter.cpp ) target_link_libraries(node_filter ${catkin_LIBRARIES} ) add_dependencies(node_filter sick_app_generate_messages_cpp) add_executable(node_classifier src/node_classifier.cpp src/constructor.cpp src/modelTool.cpp src/fileManager.cpp ) target_link_libraries(node_classifier ${catkin_LIBRARIES} ) add_dependencies(node_classifier sick_app_generate_messages_cpp) install(DIRECTORY launch DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) install(TARGETS node_filter RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}) install(TARGETS node_classifier RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}) ## Install scripts install(PROGRAMS scripts/model_classifier.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) install(PROGRAMS scripts/image_generator.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )
I don’t know why snapcraft can’t find the python modules or why they are not packed with the snap file. I’ll be so thankful if someone could help me telling me what I need to fix this problem.
Thanks.