ros / common_msgs

Commonly used messages in ROS. Includes messages for actions (actionlib_msgs), diagnostics (diagnostic_msgs), geometric primitives (geometry_msgs), robot navigation (nav_msgs), and common sensors (sensor_msgs), such as laser range finders, cameras, point clouds.
http://wiki.ros.org/common_msgs
177 stars 191 forks source link

Python can't import messages from "sensor_msgs" module #162

Closed EugeneSakun closed 4 years ago

EugeneSakun commented 4 years ago

I've built the "sensor_msgs" module from source and installed it with the following command:

catkin_make_isolated --install --pkg sensor_msgs

It works perfectly fine with other packages from the "common_msgs" repository (like "geometry_msgs" etc). But the "sensor_msgs" module wasn't recognized by Python. I got this error:

Traceback (most recent call last):
  File "/var/lib/cloud9/catkin_ws/src/bbot/scripts/imu_publisher.py", line 5, in <module>
    from sensor_msgs.msg import Imu
ImportError: No module named msg

All the "common_msgs" packages were installed to the same directory, so I checked what is the difference between "sensor_msgs" and "geometry_msgs" (the last one worked fine).

The "geometry_msgs" has a single directory in my installation directory ("dist-packages"):

-geometry_msgs/
--__init__.py
--__init__.pyc
--msg/

The "sensor_msgs" had 2 directories in "dist-packages":

-sensor_msgs/
--msg/
--srv/
-sensor_msgs-1.12.7-py2.7.egg/
--EGG-INFO
--sensor_msgs/
---__init__.py 
---__init__.pyc 
---point_cloud2.py 
---point_cloud2.pyc

Python only recognized the second directory (sensor_msgs-1.12.7-py2.7.egg), but this one didn't have any message files except the "point_cloud2".

I found a way to fix it for me: I removed the "catkin_python_setup()" line from "sensor_msgs/CMakeLists.txt" file and "<buildtool_depend condition="$ROS_PYTHON_VERSION..." lines from "sensor_msgs/package.xml" and then rebuilt it. I am not sure how and why, but this solved my issue. Maybe, this information will be useful for someone to fix it in the future.

After the fix, the "sensor_msgs" directory looks like this (and works fine):

-sensor_msgs/
--__init__.py 
--__init__.pyc
--msg/
--srv/

My environment: ARM (32-bit) Debian GNU/Linux 9 ROS Melodic Python v2.7.13 sensor_msgs version: 1.12.7

Eugene

tfoote commented 4 years ago

It sounds like you have a slighly non-standard setup. If you need more help debugging this, please ask you question on http://answers.ros.org according to our support policy: http://wiki.ros.org/Support We try to keep the issue tracker reserved for bugs and feature developments.

When you do please make sure to provide enough information to fully reproduce the problem. with your whole environment.