Error importing sensor_msgs/JointState

asked 2020-03-30 20:30:17 -0500

abdullahsorathia gravatar image

Hi, I am trying to run ROS on windows and to do that i followed this tutorial http://wiki.ros.org/Installation/Windows I created a shortcut for Ros Command window from step 6 of the tutorial and than opened the window to test come code. while testing I got error during importing of python package.

>>> from sensor_msgs.msg import JointState
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named msg

but when importing just sensor_msg it works fine

After further looking into the problem location of the package I found was

>>> import sensor_msgs
>>> import os
>>> print(sensor_msgs.__file__)
C:\opt\ros\melodic\x64\lib\site-packages\sensor_msgs-1.12.7-py2.7.egg\sensor_msgs\__init__.py

And at this location there was a folder named as sensor_msgs and a file sensor_msgs-1.12.7-py2.7.egg

sensor_msgs folder did have msg package

dir C:\opt\ros\melodic\x64\lib\site-packages\sensor_msgs\msg
 _JointState.py
 _JointState.pyc

but was absent inside sensor_msgs-1.12.7-py2.7.egg

How can I import JointState when python is accessing sensor_msgs-1.12.7-py2.7.egg which does not have JointState instead of sensor_msgs folder which has one?

edit retag flag offensive close merge delete

Comments

This seems rather similar to ms-iot/ROSOnWindows#202.

Also:

How can I import JointState when python is accessing sensor_msgs-1.12.7-py2.7.egg which does not have JointState instead of sensor_msgs folder which has one?

that's not really how Python works. I don't believe what you write there is the cause.

gvdhoorn gravatar image gvdhoorn  ( 2020-03-31 02:46:11 -0500 )edit

yes it is the same issue not able to import sensor_msgs.msg

abdullahsorathia gravatar image abdullahsorathia  ( 2020-03-31 07:16:27 -0500 )edit
1

sensor_msgs from sensor_msgs-1.12.7-py2.7.egg does not match the content of C:\opt\ros\melodic\x64\lib\site-packages\sensor_msgs

Try

import sensor_msgs
print(dir(sensor_msgs))

You will see that sensor_msgs are missing msg

A quick fix could be to make a new sensor_msgs-1.12.7-py2.7.egg from C:\opt\ros\melodic\x64\lib\site-packages\sensor_msgs or import from the folder directly.

void32 gravatar image void32  ( 2020-03-31 10:31:27 -0500 )edit

Thank you, I was able to make it work by taking backup and replacing sensor_msgs-1.12.7-py2.7.egg with the new sensor_msgs-1.12.7-py2.7.egg made from the content of C:\opt\ros\melodic\x64\lib\site-packages\sensor_msgs folder

abdullahsorathia gravatar image abdullahsorathia  ( 2020-03-31 14:47:30 -0500 )edit

For anyone else coming here, this is the latest comment by @OoeyGUI on ms-iot/ROSOnWindows#202:

We are preparing an updated release.

gvdhoorn gravatar image gvdhoorn  ( 2020-04-02 12:09:31 -0500 )edit