Roscore in Melodic not working after installing python3
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?
Asked by Nabil Miri on 2023-01-20 18:48:29 UTC
Answers
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
Asked by malwaru on 2023-01-21 11:41:27 UTC
Comments
Which files I should check to find that alias? I created an alias in .bash_profile but nothing changed. Same error
Asked by Nabil Miri on 2023-02-21 17:12:19 UTC
https://unix.stackexchange.com/questions/410579/change-the-python3-default-version-in-ubuntu
try this answer
Asked by malwaru on 2023-02-22 04:50:26 UTC
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
Asked by Mike Scheutzow on 2023-02-25 09:23:05 UTC
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
Asked by Nabil Miri on 2023-02-21 17:15:25 UTC
Comments