ImportError: No module named srv(Kinetic)
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 !
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 asrv
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.
And for future questions: please always remove all the boilerplate comments (lines starting with
#
) from yourCMakeLists.txt
. Almost 95% of the lines in the file you show are comments, making it difficult to find the lines that are not comments.Thank you for your advise!
I'm appreciated!
Sorry, I will be careful.
I referred to this Tutorial.
link text
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
androscreate-pkg
. Those are no longer supported in recent versions of ROS. Seeing yourCMakeLists.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).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
before
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?