AttributeError's when running Python scripts

asked 2020-10-09 00:37:51 -0500

soulfutterer gravatar image

updated 2020-10-09 02:35:55 -0500

I am on Ubuntu 18.04 and installed ROS Melodic.

In this tutorial on reading bag files I get the somewhat common error AttributeError: module 'enum' has no attribute 'IntFlag' The full error message is:

Traceback (most recent call last):
  File "/usr/lib/command-not-found", line 23, in <module>
    import gettext
  File "/usr/lib/python3.6/gettext.py", line 49, in <module>
    import locale, copy, io, os, re, struct, sys
  File "/usr/lib/python3.6/locale.py", line 16, in <module>
    import re
  File "/usr/lib/python3.6/re.py", line 142, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 62, in apport_excepthook
    if not enabled():
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
    import re
  File "/usr/lib/python3.6/re.py", line 142, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/command-not-found", line 23, in <module>
    import gettext
  File "/usr/lib/python3.6/gettext.py", line 49, in <module>
    import locale, copy, io, os, re, struct, sys
  File "/usr/lib/python3.6/locale.py", line 16, in <module>
    import re
  File "/usr/lib/python3.6/re.py", line 142, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

It looks like the Python versions are getting mixed up. 'python --version' returns 'Python 2.7.17' and 'echo $PYTHONPATH' returns echo '/opt/ros/melodic/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages'.

So why does it try to use python3.6?

EDIT: I don't know why, but unsetting PYTHONPATH resolved the issue.

edit retag flag offensive close merge delete