ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

ImportError: No module named msg

asked 2018-04-06 05:35:26 -0600

kwint gravatar image

updated 2018-04-06 06:16:54 -0600

I have to msg files in a msg folder. Added both msg to the CMakeList.txt and followed the instructions in the file, so the package.xml has the right dependencies. I also followed these answers on this similar questions: https://answers.ros.org/question/1057... and https://answers.ros.org/question/2716...

But i still get the following error:

Traceback (most recent call last):
  File "/home/ubuntu/catkin_ws/src/pozyx_ros_examples/src/pozyx_node.py", line 7, in <module>
    from pozyx_ros_examples.msg import DeviceRange, EulerAngles
ImportError: No module named msg

My package.xml and CMakeLists.txt are in gist: https://gist.github.com/kwint/09ab135...

I'm running lubuntu 16.04 on a raspberry pi.

.
├── CMakeLists.txt
├── __init__.py
├── msg
│   ├── DeviceRange.msg
│   ├── EulerAngles.msg
│   └── __init__.py
├── package.xml
└── src
    ├── pozyx_node.py
    └── setup_nodes
        └── pozyx_configuration.py

The weird thing is that when I run this package on my local computer it works perfectly (which runs ubuntu 16.04)

edit retag flag offensive close merge delete

Comments

did you compile the package with catkin_make? This is required to generate the respective python modules/C++ headers...

mgruhler gravatar image mgruhler  ( 2018-04-06 06:06:29 -0600 )edit

Yes I have, also source the setup.bash file

kwint gravatar image kwint  ( 2018-04-06 06:16:12 -0600 )edit

1 Answer

Sort by » oldest newest most voted
3

answered 2018-04-06 06:59:17 -0600

gvdhoorn gravatar image

updated 2018-04-06 07:33:05 -0600

Did you put the __init__.py in the msg sub dir? If so: remove it, remove your build and devel folder, rebuild your workspace and see whether things start working.


Edit:

That might have been the solution, __init__.py was empty. But I make a completely new ros module and just copied the msg files and scripts to it, now it works. I have know idea why exactly, but ok

You should not place any __init__.py files anywhere except when you're creating Python modules. ROS msgs (so the .msg files) are not modules. The code generated from them becomes a module, but that is all done automatically for you.

The __init__.py in your package root and the msg subdir should not be there. Only if you're creating a Python module, you place one in the subdir that stores the sources for your module.

edit flag offensive delete link more

Comments

That might have been the solution, __init__.py was empty. But I make a completely new ros module and just copied the msg files and scripts to it, now it works. I have know idea why exactly, but ok

kwint gravatar image kwint  ( 2018-04-06 07:22:27 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-04-06 05:35:26 -0600

Seen: 1,669 times

Last updated: Apr 06 '18