Ask Your Question

No module named srv

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

dptsrk gravatar image

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

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


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

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

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

dkurzaj gravatar imagedkurzaj ( 2016-07-27 07:20:33 -0600 )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 -0600 )edit

3 Answers

Sort by » oldest newest most voted

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

KruseT gravatar image

The module srv is a python module, which in practice just means a folder named srv with a 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


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 -0600 )edit

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

dkurzaj gravatar image

I had this error because of module name conflict.


  | src/
    | package/
      | srv/
        | service.srv
      | scripts

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

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

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

edit flag offensive delete link more



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 -0600 )edit

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

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

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

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


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

Seen: 9,159 times

Last updated: Aug 01 '16