ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Importing python module from another ROS package. (Hydro) [closed]

asked 2015-02-17 04:47:41 -0500

astur gravatar image

updated 2015-02-26 08:59:02 -0500

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/Cre...

http://answers.ros.org/question/11794...

http://docs.ros.org/api/catkin/html/h...

I sourced it ( devel/setup.bash in catkin_ws_ruben )

echo $ROS_PACKAGE_PATH

/home/robin/catkin_ws_ruben/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 flexbotics_control_nextage_teleop_ps3.


/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)

flexbotics_control_nextage_teleop_ps3 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 ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by astur
close date 2015-03-02 03:07:25.614656

Comments

Can you post the CMakeLists.txt and setup.py of the flexbotics_control_nextage_teleop_ps3 package? Also, try

from flexbotics_control_nextage_teleop_ps3.hiro_motion_savingpointsxml import *
Chrissi gravatar image Chrissi  ( 2015-02-26 05:21:29 -0500 )edit

Make sure you sourced devel/setup.bash in catkin_ws_ruben, that should put your package directory into PYTHONPATH (it's not clear from your post).

130s gravatar image 130s  ( 2015-02-26 06:13:47 -0500 )edit

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

astur gravatar image astur  ( 2015-02-26 08:31:28 -0500 )edit

Moreover, if i run both (rqt and my node) , without flexbotics_control_nextage_teleop_ps3 import hiro_motion_savingpointsxml it work perfect.

astur gravatar image astur  ( 2015-02-26 08:33:33 -0500 )edit

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

astur gravatar image astur  ( 2015-02-26 08:52:15 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2015-02-26 11:44:30 -0500

Chrissi gravatar image

updated 2015-02-26 11:45:13 -0500

Please uncomment this line

# catkin_python_setup()

In the CMakeLists.txt. otherwise the setup.py is never called.

edit flag offensive delete link more

Comments

That solve my problem,

Thank you

astur gravatar image astur  ( 2015-03-02 03:03:40 -0500 )edit

You're welcome.

Chrissi gravatar image Chrissi  ( 2015-03-02 05:05:18 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-02-17 04:47:41 -0500

Seen: 7,984 times

Last updated: Feb 26 '15