ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Roscore in Melodic not working after installing python3

asked 2023-01-20 17:48:29 -0500

Nabil Miri gravatar image

updated 2023-01-20 17:50:00 -0500

Hello, I was trying to install python 3.9 to communicate between robotics system toolbox in Matlab and ROS. But, after doing that the roscore stopped working. The obvious reason is the python3 installation as the roscore started to run using python3 as in the below error:

 AttributeError: module 'enum' has no attribute 'IntFlag'
RLException: Invalid <param> tag: Cannot load command parameter [rosversion]: command [['rosversion', 'roslaunch']] returned with code [1]. 

Param xml is <param command="rosversion roslaunch" name="rosversion"/>
The traceback for the exception was written to the log file

My ROS Distribution is Melodic.

I checked the the default prarams but they are correct:

nabil@nabil-Ideapad:~$ which python'

/usr/bin/python

and

nabil@nabil-Ideapad:~$ echo $PYTHONPATH

/opt/ros/melodic/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages

and ROS_PYTHON_VERSION=2

What can I do to fix this issue?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2023-01-21 10:41:27 -0500

malwaru gravatar image

When running roscore ROS uses the default python that you have set. The

/usr/bin/python

output you see is an alias (just a name substitution) not the real python version you are using . Follow this link and set your python version to python2.7 . It should do the trick

edit flag offensive delete link more

Comments

Which files I should check to find that alias? I created an alias in .bash_profile but nothing changed. Same error

Nabil Miri gravatar image Nabil Miri  ( 2023-02-21 16:12:19 -0500 )edit
malwaru gravatar image malwaru  ( 2023-02-22 03:50:26 -0500 )edit

I assume you are using ubuntu 18. The file /usr/bin/python is a symbolic link, and this link must point to python2.7 if you want ROS to work correctly. Here is what ls should show you:

$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Apr 16  2018 /usr/bin/python -> python2.7
Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-02-25 08:23:05 -0500 )edit
0

answered 2023-02-21 16:15:25 -0500

Nabil Miri gravatar image

This is the full error message.

nabil@nabil-Ideapad:~$ roscore
... logging to /home/nabil/.ros/log/bad5fa44-b234-11ed-82e8-9822efcf11bb/roslaunch-nabil-Ideapad-7538.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

Error processing line 1 of /usr/lib/python3/dist-packages/matplotlib-2.1.1-nspkg.pth:

Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "/usr/lib/python3.9/site.py", line 175, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.9/importlib/util.py", line 2, in <module>
    from . import abc
  File "/usr/lib/python3.9/importlib/abc.py", line 17, in <module>
    from typing import Protocol, runtime_checkable
  File "/usr/lib/python3.9/typing.py", line 26, in <module>
    import re as stdlib_re  # Avoid confusion with the re we export.
  File "/usr/lib/python3.9/re.py", line 145, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site.py", line 605, in <module>
    main()
  File "/usr/lib/python3.9/site.py", line 592, in main
    known_paths = addsitepackages(known_paths)
  File "/usr/lib/python3.9/site.py", line 375, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "/usr/lib/python3.9/site.py", line 214, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "/usr/lib/python3.9/site.py", line 185, in addpackage
    import traceback
  File "/usr/lib/python3.9/traceback.py", line 5, in <module>
    import linecache
  File "/usr/lib/python3.9/linecache.py", line 11, in <module>
    import tokenize
  File "/usr/lib/python3.9/tokenize.py", line 32, in <module>
    import re
  File "/usr/lib/python3.9/re.py", line 145, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
RLException: Invalid <param> tag: Cannot load command parameter [rosversion]: command [['rosversion', 'roslaunch']] returned with code [1]. 

Param xml is <param command="rosversion roslaunch" name="rosversion"/>
The traceback for the exception was written to the log file
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2023-01-20 17:48:29 -0500

Seen: 269 times

Last updated: Feb 21 '23