ImportError: No module named srv(Kinetic)

asked 2019-10-22 10:32:52 -0500

K.T gravatar image

updated 2019-10-23 03:01:07 -0500

gvdhoorn gravatar image

Hello,

I was trying to do the PR2 tutorial - Getting the current joint angles with ROS Kinetic Kame in Ubuntu 16.04 but I'm stuck with a problem regarding the import of the service message. I keep getting the following error when trying to run the service node:

$rosrun joint_states_listener joint_states_listener.py

        Traceback (most recent call last):
    File "../catkin_ws/src/joint_states_listener/src/joint_states_listener.py", line 8, in <module>
    from joint_states_listener.srv import *
    File "../catkin_ws/src/joint_states_listener/src/joint_states_listener.py", line 8, in <module>
    from joint_states_listener.srv import *
    ImportError: No module named srv

My package contains a .srv file called ReturnJointStates.srv as mentioned in the tutorial.

The begginer's tutorial regarding services works fine.

My CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 2.8.3)
project(joint_states_listener)

find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  roscpp
  rospy
  std_msgs
  message_generation
  sensor_msgs
  actionlib_msgs
)

add_message_files(
 FILES
 joint_states_listener.msg
)

add_service_files(
 FILES
 ReturnJointStates.srv
)

generate_messages(
 DEPENDENCIES
 std_msgs
 geometry_msgs
 sensor_msgs 
)

catkin_package(CATKIN_DEPENDS
 message_runtime
 rospy
 geometry_msgs
 std_msgs
 sensor_msgs
)

Any ideas or help would be really appreciated !

edit retag flag offensive close merge delete

Comments

1

First: please always link to any tutorial you may be following. "The PR2 tutorial" is not sufficient to easily find what you refer to.

As to your issue: I believe this may be caused by the fact that your script is also called joint_states_listener, just as your package is. The Python interpreter may be trying to locate a srv sub module inside that, which doesn't exist.

As I don't know which tutorial you are doing, I can't say whether the exact filename of the script matters, but if it doesn't, I'd recommend trying to rename it and see whether that fixes things.

gvdhoorn gravatar image gvdhoorn  ( 2019-10-22 12:24:56 -0500 )edit
1

And for future questions: please always remove all the boilerplate comments (lines starting with #) from your CMakeLists.txt. Almost 95% of the lines in the file you show are comments, making it difficult to find the lines that are not comments.

gvdhoorn gravatar image gvdhoorn  ( 2019-10-22 12:25:51 -0500 )edit

Thank you for your advise!

I'm appreciated!

Sorry, I will be careful.

I referred to this Tutorial.

link text

K.T gravatar image K.T  ( 2019-10-22 21:35:03 -0500 )edit

So have you tried changing the name of your script?

Please also note that the tutorial you link to is very old (last edit was on 2010-09-18) and still mentions rosbuild and roscreate-pkg. Those are no longer supported in recent versions of ROS. Seeing your CMakeLists.txt it appears you've already converted things to Catkin, but it could still be that things don't work as explained in the rest of the tutorial (I haven't checked).

gvdhoorn gravatar image gvdhoorn  ( 2019-10-23 04:06:25 -0500 )edit

Is your package.xml correctly configured? can you give us alsto this information?

btw did you source correctly the terminal you are using? something like

source ~/catkin_ws/devel/setup.bash

before

catkin_make
Solrac3589 gravatar image Solrac3589  ( 2019-10-23 07:23:00 -0500 )edit

Suggest checking python path to make sure it contains the directory of the file.

echo $PYTHONPATH

Also, do you have something like

#!/usr/bin/env python

as the first line of the file?

billy gravatar image billy  ( 2019-10-25 01:20:55 -0500 )edit