Robotics StackExchange | Archived questions

ModuleNotFoundError: No module named 'error'

When importing rospy in python 3.6 I get the following error:

Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rospy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 47, in <module>
    from std_msgs.msg import Header
  File "/opt/ros/melodic/lib/python2.7/dist-packages/std_msgs/msg/__init__.py", line 1, in <module>
    from ._Bool import *
  File "/opt/ros/melodic/lib/python2.7/dist-packages/std_msgs/msg/_Bool.py", line 5, in <module>
    import genpy
  File "/opt/ros/melodic/lib/python2.7/dist-packages/genpy/__init__.py", line 34, in <module>
    from . message import Message, SerializationError, DeserializationError, MessageException, struct_I
  File "/opt/ros/melodic/lib/python2.7/dist-packages/genpy/message.py", line 47, in <module>
    import yaml
  File "/usr/lib/python2.7/dist-packages/yaml/__init__.py", line 2, in <module>
    from error import *
ModuleNotFoundError: No module named 'error'

I just can't figure out why. Does anyone know what could cause this?

Asked by rosNewbie on 2020-06-25 10:28:52 UTC

Comments

Does anyone know what could cause this?

ROS Melodic does not support Python 3.

You must have done something 'special' to get this far. It would be good to tell us what.

Note: mixing Python 2 and Python 3 without special consideration for compatibility and package search paths is going to be brittle at best.

If you need to use Python 3, migrate to ROS Noetic, or use something like rospypi/simple.

Asked by gvdhoorn on 2020-06-26 03:00:02 UTC

@gvdhoorn I use cv_bridge, and did what is told in this answer. I created another catkin_workspace with py3 and source it as --extend into my other workspace.

Asked by rosNewbie on 2020-06-26 04:42:11 UTC

It would have been better if the poster of the answer you link could have been a bit more careful with just telling everyone to use --extend when sourceing. It's not recommended to do that unless you know what you are doing, in essence exactly because it can cause the problems you are running into now.

Asked by gvdhoorn on 2020-06-26 05:16:53 UTC

@gvdhoorn Do you have any advice how to solve my problem?

Asked by rosNewbie on 2020-06-26 05:48:46 UTC

I would sugget to not use --extend, to start with.

Yes, that will mean you cannot mix-and-match your "regular" packages with the ones you build with Python 3, but that is not supported (officially).

Asked by gvdhoorn on 2020-06-26 05:55:22 UTC

@gvdhoorn, unfortunately this is not really an option for me. I use a code base from another person. And there this was done like this. I just try to get it running on my ubuntu 18.04

Asked by rosNewbie on 2020-06-26 06:08:55 UTC

Then I would suggest you ask the author how he did this.

The underlying problem is that your Python3 interpreter is trying to load Python2 packages (specifically PyYaml in this case), which is what's causing the import error.

This is most likely caused by the PYTHONPATH placing Python 2 packages before Python 3 ones.

This is most likely caused by the fact that --extend appends values to the current environment, instead of overriding it.

Asked by gvdhoorn on 2020-06-26 06:15:15 UTC

Answers