Importing python module from another ROS package. (Hydro)
I followed tutorials and other questions relationated with this topic but I can't figure what I'm doing wrong.
http://wiki.ros.org/rqt/Tutorials/Create%20your%20new%20rqt%20plugin
http://answers.ros.org/question/11794/how-can-i-use-custom-python-functions-in-other-ros-packages/
http://docs.ros.org/api/catkin/html/howto/format2/installing_python.html
I sourced it ( devel/setup.bash in catkinwsruben )
echo $ROSPACKAGEPATH
/home/robin/catkinwsruben/src:/opt/ros/hydro/share:/opt/ros/hydro/stacks
and do also catkin_make clean
My problem:
I want to include this node on my my_module.py
from flexbotics_control_nextage_teleop_ps3 import hiro_motion_savingpointsxml
and show me ImportError: No module named flexboticscontrolnextageteleopps3.
/catkin_ws_ruben
/build
/devel
/src
/flexbotics_control_nextage_teleop_ps3
/scripts
|.....
|__init__.py
/src
/flexbotics_control_nextage_teleop_ps3
|hiro_motion_savingpointsxml.py
|__init__.py
/config
/launch
setup.py
__init__.py
CMakeLists.txt
/rqt_mypkg
/scripts
/src
/rqt_mypkg
|my_module.py
|my_module.pyc
|__init__.py
/resource
|MyPlugin.ui
setup.py
__init__.py
package.xml
CMakeLists.txt
rqt_mypkg:
CMakeList
cmake_minimum_required(VERSION 2.8.3)
project(rqt_mypkg)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
rospy
rqt_gui
rqt_gui_py
std_msgs
flexbotics_control_nextage_teleop_ps3
)
catkin_python_setup()
## Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
std_msgs # Or other packages containing msgs
)
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES rqt_mypkg
# CATKIN_DEPENDS rospy rqt_gui rqt_gui_py
# DEPENDS system_lib
CATKIN_DEPENDS message_runtime
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
${catkin_INCLUDE_DIRS}
)
install(PROGRAMS src/rqt_mypkg/my_module.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
package:
<?xml version="1.0"?>
<package>
<name>rqt_mypkg</name>
<version>0.0.0</version>
<description>The rqt_mypkg package</description>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>rospy</build_depend>
<build_depend>rqt_gui</build_depend>
<build_depend>rqt_gui_py</build_depend>
<build_depend>message_generation</build_depend>
<build_depend>flexbotics_control_nextage_teleop_ps3</build_depend>
<run_depend>rospy</run_depend>
<run_depend>rqt_gui</run_depend>
<run_depend>rqt_gui_py</run_depend>
<run_depend>flexbotics_control_nextage_teleop_ps3</run_depend>
<run_depend>message_runtime</run_depend>
<!-- The export tag contains other, unspecified, tags -->
<export>
<rqt_gui plugin="${prefix}/plugin.xml"/>
</export>
</package>
setup.py
#!/usr/bin/env python
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
d = generate_distutils_setup(
packages=['rqt_mypkg'],
package_dir={'': 'src'}
)
setup(**d)
flexboticscontrolnextageteleopps3 package:
setup.py:
#!/usr/bin/env python
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
d = generate_distutils_setup(
packages=['flexbotics_control_nextage_teleop_ps3'],
package_dir={'': 'src'}
)
setup(**d)
CMakeList:
cmake_minimum_required(VERSION 2.8.3)
project(flexbotics_control_nextage_teleop_ps3)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
joy
moveit_commander
moveit_msgs
roscpp
rospy
std_msgs
message_generation
)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()
################################################
## Declare ROS messages, services and actions ##
################################################
## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependencies might have been
## pulled in transitively but can be declared for certainty nonetheless:
## * add a build_depend tag for "message_generation"
## * add a run_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
## Generate services in the 'srv' folder
# add_service_files(
# FILES
#
#
#)
## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )
## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# moveit_msgs# std_msgs
# )
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES teleoperacion_hiro
# CATKIN_DEPENDS joy moveit_commander moveit_msgs roscpp rospy std_msgs
# DEPENDS system_lib
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
${catkin_INCLUDE_DIRS}
)
Errors:
RosPluginProvider.load(rqt_mypkg/My Plugin) exception raised in __builtin__.__import__(rqt_mypkg.my_module, [MyPlugin]):
Traceback (most recent call last):
File "/opt/ros/hydro/lib/python2.7/dist-packages/rqt_gui/ros_plugin_provider.py", line 77, in load
module = __builtin__.__import__(attributes['module_name'], fromlist=[attributes['class_from_class_type']], level=0)
File "/home/robin/catkin_ws_ruben/src/rqt_mypkg/src/rqt_mypkg/my_module.py", line 21, in <module>
from flexbotics_control_nextage_teleop_ps3 import hiro_motion_savingpointsxml
ImportError: No module named flexbotics_control_nextage_teleop_ps3
PluginManager._load_plugin() could not load plugin "rqt_mypkg/My Plugin":
Traceback (most recent call last):
File "/opt/ros/hydro/lib/python2.7/dist-packages/qt_gui/plugin_handler.py", line 98, in load
self._load()
File "/opt/ros/hydro/lib/python2.7/dist-packages/qt_gui/plugin_handler_direct.py", line 54, in _load
self._plugin = self._plugin_provider.load(self._instance_id.plugin_id, self._context)
File "/opt/ros/hydro/lib/python2.7/dist-packages/qt_gui/composite_plugin_provider.py", line 71, in load
instance = plugin_provider.load(plugin_id, plugin_context)
File "/opt/ros/hydro/lib/python2.7/dist-packages/qt_gui/composite_plugin_provider.py", line 71, in load
instance = plugin_provider.load(plugin_id, plugin_context)
File "/opt/ros/hydro/lib/python2.7/dist-packages/rqt_gui_py/ros_py_plugin_provider.py", line 60, in load
return super(RosPyPluginProvider, self).load(plugin_id, plugin_context)
File "/opt/ros/hydro/lib/python2.7/dist-packages/qt_gui/composite_plugin_provider.py", line 71, in load
instance = plugin_provider.load(plugin_id, plugin_context)
File "/opt/ros/hydro/lib/python2.7/dist-packages/rqt_gui/ros_plugin_provider.py", line 83, in load
raise e
ImportError: No module named flexbotics_control_nextage_teleop_ps3
Thanks for your time
Asked by astur on 2015-02-17 05:47:41 UTC
Comments
Can you post the CMakeLists.txt and setup.py of the flexbotics_control_nextage_teleop_ps3 package? Also, try
Asked by Chrissi on 2015-02-26 06:21:29 UTC
Make sure you sourced
devel/setup.bash
incatkin_ws_ruben
, that should put your package directory intoPYTHONPATH
(it's not clear from your post).Asked by 130s on 2015-02-26 07:13:47 UTC
I try from flexbotics_control_nextage_teleop_ps3.hiro_motion_savingpointsxml import * and same error:
ImportError: No module named flexbotics_control_nextage_teleop_ps3.hiro_motion_savingpointsxml
Asked by astur on 2015-02-26 09:31:28 UTC
Moreover, if i run both (rqt and my node) , without flexbotics_control_nextage_teleop_ps3 import hiro_motion_savingpointsxml it work perfect.
Asked by astur on 2015-02-26 09:33:33 UTC
I did it some time ago "sourced devel/setup.bash"
echo $ROS_PACKAGE_PATH /home/robin/catkin_ws_ruben/src:/opt/ros/hydro/share:/opt/ros/hydro/stacks
Asked by astur on 2015-02-26 09:52:15 UTC