0
$\begingroup$

Rosanswers logo

Hello,

I have a package called skeleton_markers that I am in the process of converting from rosbuild to catkin. The package builds fine and I remembered to do a 'source devel/setup.bash' after compiling. But when I try to run a Python node (in the same package) that imports a message type defined in my package, I get the error:

Traceback (most recent call last):
  File "/home/patrick/catkin_ws/src/skeleton_markers/nodes/skeleton_markers.py", line 24, in <module>
    from skeleton_markers.msg import Skeleton
  File "/home/patrick/Dropbox/Robotics/catkin_ws/src/skeleton_markers/nodes/skeleton_markers.py", line 24, in <module>
    from skeleton_markers.msg import Skeleton
ImportError: No module named msg

When I run rosmsg on the message type, I get back the correct response:

$ rosmsg show skeleton_markers/Skeleton std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
int32 user_id
string[] name
float32[] confidence
geometry_msgs/Vector3[] position
  float64 x
  float64 y
  float64 z
geometry_msgs/Quaternion[] orientation
  float64 x
  float64 y
  float64 z
  float64 w

So I'm guessing I'm missing a key ingredient that allows a Python node to import my message type. Here are my package.xml and CMakeLists.txt files. The Python node I am trying to run is skeleton_markers.py.

My package.xml file:

<package>
  <name>skeleton_markers</name>
  <version>0.4.0</version>
  <description>
   Skeleton Markers: Publish a list of joint markers 
   for viewing in RViz.
  </description>

  <maintainer email="[email protected]">Patrick Goebel</maintainer>
  <license>BSD</license>
  <url type="website">http://ros.org/wiki/skeleton_markers</url>
  <url type="https://github.com/pirobot/skeleton_markers/issues"></url>
  <author email="[email protected]">Patrick Goebel</author>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>libopenni-dev</build_depend>
  <build_depend>libopenni-nite-dev</build_depend>
  <build_depend>libopenni-sensor-primesense-dev</build_depend>
  <build_depend>geometry_msgs</build_depend>
  <build_depend>tf</build_depend>
  <build_depend>orocos_kdl</build_depend>
  <build_depend>message_generation</build_depend>
  <build_depend>visualization_msgs</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>geometry_msgs</build_depend>
  <build_depend>openni_camera</build_depend>
  <build_depend>openni_tracker</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>roscpp</build_depend>

  <run_depend>libopenni-dev</run_depend>
  <run_depend>libopenni-nite-dev</run_depend>
  <run_depend>libopenni-sensor-primesense-dev</run_depend>
  <run_depend>geometry_msgs</run_depend>
  <run_depend>orocos_kdl</run_depend>
  <run_depend>message_runtime</run_depend>
  <run_depend>visualization_msgs</run_depend>
  <run_depend>std_msgs</run_depend>
  <run_depend>geometry_msgs</run_depend>
  <run_depend>tf</run_depend>
  <run_depend>openni_camera</run_depend>
  <run_depend>openni_tracker</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>roscpp</run_depend>

</package>

My CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8.3)
project(skeleton_markers)

find_package(orocos_kdl REQUIRED)
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  tf
  geometry_msgs
  message_generation)

# Find OpenNI
find_package(PkgConfig)
pkg_check_modules(OpenNI REQUIRED libopenni)

# Find Nite
find_path(Nite_INCLUDEDIR
          NAMES XnVNite.h
          HINTS /usr/include/nite /usr/local/include/nite)
find_library(Nite_LIBRARY
             NAMES XnVNite_1_3_1
             HINTS /usr/lib /usr/local/lib
             PATH_SUFFIXES lib) 

link_directories(
  ${catkin_LIBRARY_DIRS}
  ${Boost_LIBRARY_DIRS}
  ${orocos_kdl_LIBRARY_DIRS}
  ${OpenNI_LIBRARIES}
  ${Nite_LIBRARY}
)

include_directories(${catkin_INCLUDEDIR}
                    ${OpenNI_INCLUDEDIR}
                    ${Nite_INCLUDEDIR}
                    ${orocos_kdl_INCLUDE_DIRS})

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

add_message_files (
  FILES
  Skeleton.msg
)

generate_messages(
  DEPENDENCIES geometry_msgs std_msgs
)

catkin_package(
    DEPENDS rospy roscpp visualization_msgs std_msgs geometry_msgs
    openni_camera openni_tracker tf
    CATKIN-DEPENDS message_runtime
    INCLUDE_DIRS # TODO
    LIBRARIES # TODO
)

add_executable(skeleton_tracker
  src/skeleton_tracker.cpp
  src/KinectController.cpp
  src/KinectDisplay.cpp)

target_link_libraries(skeleton_tracker
  glut
  ${catkin_LIBRARIES}
  ${OpenNI_LIBRARIES}
  ${Nite_LIBRARY}
  ${orocos_kdl_LIBRARIES})

install(TARGETS skeleton_tracker RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

Thanks!
patrick

UPDATE: I added the following setup.py file to the top level of my skeleton_markers package and I added the line:

catkin_python_setup()

to my CMakeLists.txt file. Unfortunately, this did not fix the import problem even after a clean rebuild and doing a 'source devel/setup.bash'.

setup.py:

## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

# fetch values from package.xml
setup_args = generate_distutils_setup(
    packages=['skeleton_markers'],
    package_dir={'': 'src'})

setup(**setup_args)

Originally posted by Pi Robot on ROS Answers with karma: 4046 on 2013-12-29

Post score: 2


Original comments

Comment by joq on 2013-12-29:
Was it built successfully? Your Python message file should be in your workspace at: devel/lib/python2.7/dist-packages/skeleton_markers/msg/_Skeleton.py

Comment by Pi Robot on 2013-12-29:
Yes, the package builds successfully and the msg file you refer to does exist in the correct location.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

I think your problem is that your python script is called skeleton_markers.py, and python is looking for the msg module in that script. If you rename it such that it doesn't have the same name as your package, does it work?


Originally posted by lindzey with karma: 1780 on 2013-12-29

This answer was ACCEPTED on the original site

Post score: 15


Original comments

Comment by Pi Robot on 2013-12-29:
Awesome! That was it exactly. Never would have thought of that...Many thanks!

Comment by jpaulos on 2014-02-28:
Had a similar issue, also solved my problem. Note that you will need clear out the old .pyc file as well, if it exists.

Comment by antonio on 2016-06-22:
This solved my problem _

Comment by Falko on 2016-12-15:
In my case there was another - currently unused - file with the same name within that directory. Never thought of it until reading this post.

$\endgroup$
0
$\begingroup$

Rosanswers logo

You should not modify the output directories for libraries and executables - remove the following lines from your CMakeLists.txt:

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

When invoking catkin_package() the optional keyword argument is CATKIN_DEPENDS (not CATKIN-DEPENDS). Please consider reading http://docs.ros.org/api/catkin/html/howto/index.html for more information when to use DEPENDS and when to use CATKIN_DEPENDS.

You should also consider filling in the other optional arguments of catkin_package(). While it will not affect your package directly it does affect packages which would depend on your package.


Originally posted by Dirk Thomas with karma: 16276 on 2013-12-29

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by Dirk Thomas on 2013-12-29:
You should update your version of catkinize if it generated the CATKIN-DEPENDS for you. This typo has been fixed 9 months ago.

Comment by Pi Robot on 2013-12-29:
Thanks for the clarification. Unfortunately, removing those two lines and recompiling did not solve the import problem. Also, you are correct that I was using an older version of the catkinize script because the newest version crashes as reported here: https://github.com/ros-infrastructure/catkinize/issues/38#issuecomment-31316935

Comment by Dirk Thomas on 2013-12-29:
My above comments will not address your import problem but only point out additional problems in the posted code. Please follow the previously given advice to create a "setup.py" file and use "catkin_python_setup()" for that.

Comment by Pi Robot on 2013-12-29:
OK, I added a setup.py file as explained in the link in @joq's Update and I added the catkin_python_setup() line to my CMakeLists.txt file. Then I did a 'rm -rf devel build', 'catkin_make' and 'source devel/setup.bash' but the import error remains.

Comment by Pi Robot on 2013-12-29:
@Dirk Thomas - just an FYI that I updated my question with my setup.py file. Not sure if I have to add something to that file specific to message files.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.