Error installing ROS Melodic on Ubuntu 18.04 (Jetson Xavier NX)

asked 2023-02-15 13:24:18 -0500

HenryInUtah gravatar image

updated 2023-02-16 02:47:26 -0500

gvdhoorn gravatar image


I have a Nvidia Jetson Xavier NX that was purchased "pre-built" as a little industrial computer. It is running Ubuntu 18.04. I tried to install ROS using the directions found on this page:

Somewhere among the pages of scrolling messages, this error scrolled by:

Setting up python-twisted-core (17.9.0-2ubuntu0.3) ...

  File "/usr/bin/pyversions", line 20

    except IOError, msg:
SyntaxError: invalid syntax

It seems like it is using Python2 code in Python3 ??? Completely a guess. Everything else seemed to install without any additional errors. I followed the rest of the instructions provided on the page.

In order to test the installation, I entered "roscore" and got the following error:

nvidia@nx:~$ roscore

Traceback (most recent call last):

  File "/opt/ros/melodic/bin/roscore", line 36, in <module>
    from rosmaster.master_api import NUM_WORKERS
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rosmaster/", line 35, in <module>
    from .main import rosmaster_main
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rosmaster/", line 43, in <module>
    import rosmaster.master
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rosmaster/", line 47, in <module>
    import rosmaster.master_api
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rosmaster/", line 72, in <module>
    from rosmaster.util import xmlrpcapi
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rosmaster/", line 48, in <module>
    from defusedxml.xmlrpc import monkey_patch
ModuleNotFoundError: No module named 'defusedxml'

I tried to uninstall the installation completely using information found here: #q57213.


sudo apt-get remove ros-*

sudo apt-get autoremove

Then I followed the installation directions again with the same result.

What should I do next to fix the error so that I can install it correctly?

Thanks for your help, Henry

edit retag flag offensive close merge delete


It seems like it is using Python2 code in Python3 ?

looks like it.

ROS Melodic really only supports Python 2. For Python 3 compatibility, you should install Noetic, but that's not available for Ubuntu 18.04 (only for 20.04).

You'll need to make sure your OS has not been setup to use Python 3 by default, or at least make sure to never use it with anything installed by the binary ros-melodic-* debian packages you've used to install ROS Melodic.

Unfortunately this isn't really a ROS problem per se. Anything which relies on Python 2 being the default would fail to work.

Additionally: in most cases, if apt encounters an error installing a package, it will abort the installation process completely (as in: it will just stop in its tracks, without continuing with "the rest" of the packages it needs to install). It's likely ...(more)

gvdhoorn gravatar image gvdhoorn  ( 2023-02-16 02:38:19 -0500 )edit

To avoid these kinds of things, and also to make using software on "strange" platforms (like the Xavier with NVIDIA's unorthodox OS image deployment and versioning approach), I like to use containers. Docker could be one option, I've also used Singularity CE.

You still have to care about CPU architecture, but apart from that you have full freedom in what you run, how and which versions, without ever having to touch anything on the host OS.

While it won't be affected by the host's Python version any more -- so in a way no longer really relevant -- this would allow you to run ROS Noetic on your system, or even ROS 2. You do need container support on the Xavier of course. That would be something to check.

gvdhoorn gravatar image gvdhoorn  ( 2023-02-16 02:50:28 -0500 )edit