Ask Your Question
4

No module named srv

asked 2013-01-19 04:22:11 -0500

dptsrk gravatar image

updated 2014-01-28 17:14:54 -0500

ngrennan gravatar image

I was following the tutorial WrittingServiceClient(Python). I have typed the code as it is. The project "makes" properly also, but when I try to rosrun the server or the client the following error shows:

from beginner_tutorials import * ImportError: No module named srv

Where am I going wrong? How to create the module srv?

N.B.: I have followed the tutorial "Creating a ROS msg and srv" and the srv file exists inside the beginner_tutorials/srv

edit retag flag offensive close merge delete

Comments

Did you sort it out? I am having exactly the same problem...

mmodetb gravatar imagemmodetb ( 2015-03-07 15:49:02 -0500 )edit

I encounter the same problem right now, has anybody found why it happens ?

dkurzaj gravatar imagedkurzaj ( 2016-07-27 07:20:33 -0500 )edit

In my case, I had to source the devel/setup.bash in each instance of the console I was calling the scripts from. Once for the client, once for the server. Then, it worked for me.

mneumann gravatar imagemneumann ( 2018-09-14 09:40:48 -0500 )edit

3 Answers

Sort by » oldest newest most voted
2

answered 2013-01-19 06:32:50 -0500

KruseT gravatar image

The module srv is a python module, which in practice just means a folder named srv with a __init__.py in it. This file is generated from .srv files you define, when building the project correctly.

With catkin, the safest way to rebuild everything is to delete your build and devel folders and rebuild everything.

edit flag offensive delete link more

Comments

I don't think this is an answer. You can remove those folders and rebuild everything, there is no guarantee that it will work. One has to check CMakeLists.txt, package.xml and the code files, all should be consistent with the package name and all that.

Jägermeister gravatar imageJägermeister ( 2019-08-05 09:29:09 -0500 )edit
6

answered 2016-08-01 04:52:36 -0500

dkurzaj gravatar image

I had this error because of module name conflict.

e.g.:

catkin_ws/
  | src/
    | package/
      | srv/
        | service.srv
      | scripts
        | package.py
        | code_using_service.py

I was importing the service into the code_using_service.py file and got the error message:

from package.srv import *
ImportError: No module named srv

It was looking for the srv module inside my package.py module instead of inside my package/ module. So I just renamed my script file to package_node.py to avoid the conflict.

edit flag offensive delete link more

Comments

1

This was my problem. To fix it I had to not only rename the script, but also make sure any pyc files were removed.

vschmidt gravatar imagevschmidt ( 2017-01-31 17:38:23 -0500 )edit

Service name and package name can be the same, right?

Jägermeister gravatar imageJägermeister ( 2019-07-29 06:55:24 -0500 )edit
3

answered 2013-01-19 06:19:20 -0500

130s gravatar image

In the tutorial Writing a Simple Service and Client (Python), do Build your nodes section and rosrun again. It seems to me you might not have generated *.srv modules. In that tutorial page, don't forget to choose your build system (if you're using rosmake, choose rosbuild).

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-01-19 04:22:11 -0500

Seen: 8,433 times

Last updated: Aug 01 '16