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

SyntaxError: invalid syntax for roscore

asked 2021-07-27 11:05:22 -0500

SlowAnnealing gravatar image

updated 2021-07-27 12:15:12 -0500

I tried to install relaunch roscore on Ubuntu 18.04 but got the following error. Any advice is greatly appreciated.

Traceback (most recent call last):
  File "/opt/ros/melodic/bin/roscore", line 72, in <module>
    import roslaunch
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/__init__.py", line 52, in <module>
    from . import param_dump as roslaunch_param_dump
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/param_dump.py", line 40, in <module>
    import roslaunch.config
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/config.py", line 45, in <module>
    import rospkg.distro
  File "/usr/lib/python2.7/dist-packages/rospkg/distro.py", line 44, in <module>
    import yaml
  File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 284
    class YAMLObject(metaclass=YAMLObjectMetaclass):
                              ^
SyntaxError: invalid syntax
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-07-27 16:24:55 -0500

Mike Scheutzow gravatar image

It appears you have not installed apt package python-yaml, and/or your environment variable PYTHONPATH is not right. If it has any entries for python3 in it, that going to cause you headaches.

edit flag offensive delete link more

Comments

Thanks for your suggestion, Mike. I believe my conda environment disrupt the ROS. The following line in ~/.bashrc was commented out but the error persist even after python-yaml is confirmed installed in my machine. #export PYTHONPATH="/usr/lib/python3/dist-packages:$PYTHONPATH"

Since there is an entry for python3, the only option is reinstall ROS Melodic. Correct?

SlowAnnealing gravatar image SlowAnnealing  ( 2021-07-27 16:58:36 -0500 )edit

You shouldn't have to. Try deleting the PYTHONPATH variable and source setup.bash again:

unset PYTHONPATH
source /opt/ros/melodic/setup.bash
Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-07-27 17:46:48 -0500 )edit

I appreciate your expertise, Mike. Your solution works perfect without any impact on conda.

SlowAnnealing gravatar image SlowAnnealing  ( 2021-07-27 18:42:56 -0500 )edit

I'm happy this got resolved, but please be mindful of posting duplicates.

See #q221035, #q11479 and perhaps even #q9791.

gvdhoorn gravatar image gvdhoorn  ( 2021-07-28 00:55:30 -0500 )edit
0

answered 2022-02-21 12:03:12 -0500

atef gravatar image

I you still facing the issue the solution works for me now is switching between python versions using this method (https://www.fosslinux.com/39384/switc...) then adding an alias of switching between the python versions in the basrc file alias switch_python_version='sudo update-alternatives --config python' then source source ~/.bashrc

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-07-27 11:05:22 -0500

Seen: 1,551 times

Last updated: Jul 27 '21