1

I am trying to install a ROS driver for a radar sensor.

The ROS publisher node is written in Python 3. It uses rosy to create messages and services.

When I call the script using $ python3 filename.py

I see the following output:

  File "umrr_can_publisher.py", line 3, in <module>
    import rospy
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 52, in <module>
    import roslib
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module>
    import rospkg
ModuleNotFoundError: No module named 'rospkg'

I also tried to run my script in a virtual environment but with the same result.

Thanks for helping.

Metz
  • 53
  • 1
  • 5

1 Answers1

4

rospkg is a Python package that is usually provided by your ROS installation. If you are using a different interpreter than that used by the ROS installation, you will need to install this package manually, for example via pip3 install rospkg.

Alternatively, if your virtual environment's interpreter is compatible with the interpreter used by your ROS installation, you may also add the path to ROS' python packages to your Python path.

Community
  • 1
  • 1
Brian
  • 2,948
  • 4
  • 13
  • 23
  • Although I am using Python 3 with ROS melodic just fine, `ros-melodic-desktop-full` does not install rospkg for Python 3. Installing via pip solved the problem. I think it should be available via the package manager, though. – Hermann Sep 14 '20 at 09:35