Ask Your Question
0

Import error in beginner tutorials

asked 2021-05-02 09:18:35 -0500

mayday-sauce gravatar image

updated 2021-05-04 02:06:02 -0500

Delb gravatar image

Hello, I am a beginner in ROS and I have been following the tutorial for simple service and client nodes: http://wiki.ros.org/ROS/Tutorials/Wri... . After following the tutorial and trying to run the program, I get the following error:

Traceback (most recent call last):
  File "/home/klara/catkin_ws/src/beginner_tutorials/scripts/add_two_ints_server.py", line 5, in <module>
    from beginner_tutorials.srv import AddTwoInts,AddTwoIntsResponse
ImportError: No module named srv

I use Ubuntu 18.04 with ROS melodic, python 2 and catkin. I have sourced the devel/setup.bash so that shouldn't be the problem.

I think the problem is in the service, because everything runs fine when I change
from beginner_tutorials.srv import AddTwoInts,AddTwoIntsResponse to
from rospy_tutorial.srv import AddTwoInts,AddTwoIntsResponse .

I have checked ~/catkin_ws/devel/share/common-lisp/ros/beginner_tutorials/srv/ and it was empty, even though the tutorials say there should be a python script generated there.

I copy pasted the package.xml from rospy_tutorial and changed the package name.

The add_two_ints_server.py is also copy-pasted from the tutorial.

I run catkin_make from catkin_ws, then source devel/setup.bash, then rosrun beginner_tutorials add_two_ints_server.py and I get the import error.

Thank you in advance for help!

This is my package:

.

├─CMakeLists.txt

├── msg

│   └── Num.msg

├── package.xml

├── scripts

│   ├── add_two_ints_server.py

│   ├── listener.py

│   └── talker.py

└── srv

    └── AddTwoInts.srv

This is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.2)

project(beginner_tutorials)

find_package(catkin REQUIRED COMPONENTS
    roscpp
    rospy
    std_msgs
    message_generation
)

add_message_files(
  FILES
  Num.msg
)

add_service_files(
  FILES
  AddTwoInts.srv
 )

generate_messages(
  DEPENDENCIES
   std_msgs  
 )

catkin_package(
  CATKIN_DEPENDS message_runtime 
)

include_directories(
 # ${catkin_INCLUDE_DIRS}
)

catkin_install_python(PROGRAMS
  scripts/talker.py scripts/listener.py scripts/add_two_ints_server.py

 DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
edit retag flag offensive close merge delete

Comments

I copy pasted the package.xml from rospy_tutorial and changed the package name.

Why did you use the package.xml from rospy_tutorial and not from the tutorial you are following ? Maybe you should start again (and properly do the modifications in package.xml and CMakeLists.txt). If it doesn't change anything maybe you could show us the package.xml you are using too. Also, is the file AddTwoInts.srv the same as in the tutorial ?

Delb gravatar image Delb  ( 2021-05-04 02:39:19 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2021-05-03 08:19:00 -0500

It looks like the catkin_package setting is not enough. Try the following.

catkin_package(
  CATKIN_DEPENDS message_runtime std_msgs # added std_msgs
)

ref: http://docs.ros.org/en/latest/api/cat...

edit flag offensive delete link more

Comments

Thank you, unfortunately, I am still getting the same error.

mayday-sauce gravatar image mayday-sauce  ( 2021-05-03 09:01:08 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-05-02 09:18:35 -0500

Seen: 43 times

Last updated: May 04