building python 3.9.1 on jetpack 4.5 and the jetson xavier nx

These instructions will help you build Python 3.9.1 on the Jetson Xavier NX Development Kit running JetPack 4.5. There are two broad stages to building this version. The first is the installation of support developer libraries to allow all Python modules to successfully build, especially _ssl. If _ssl fails to build then pip will not be able to negotiate connectivity with any Python repo, making installation of modules fail. After the installation stage come the build steps.

Install Build Prerequisites

To build all Python modules the following libraries need to be installed. Simply copy-and-paste the following line:

sudo apt install zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev

Build Python

Download the latest version of Python, build, and install:

  1. Download the latest Python, version 3.9.1, from https://www.python.org/downloads/.
  2. Untar the file (we’ll assume it’s downloaded to the default ~/Downloads):
    tar xvf Downloads/Python-3.9.1.tar.xz
  3. Make a build directory at the same level as the untarred source directory. In my case I named the build directory build-python-3.9.1
  4. Change directory into the build directory.
  5. From within the build directory execute the configure script:
    ../Python-3.9.1/configure --enable-optimizations
  6. Run make with all active cores:
    make -j $(nproc)

    On my machine I enabled all six cores of the Jetson Xavier NX. Running with fewer cores will result in a longer build time.

  7. Install into the alternate location for this version of Python:
    sudo -H make altinstall
  8. Check for the alternate location with which python3.9. It should return /usr/local/bin/python3.9.

I created a Python 3.9.1 virtual work environment, something I highly recommend. I do that to keep the stock and newly installed environments distinct from one another. These are the specific steps I used to create that virtual Python environment.

  1. In your home directory create a work folder. On my system I named it ‘vpython’. Change directory (cd) into it.
  2. Then create a Python VE:
    python3.9 -m venv 39
  3. While you’re there you might as well update pip. Always count on the pip bundled with any version to be out of date with the official version. Using my environment as an example:
    $HOME/vpython/39/bin/python3.9 -m pip install --upgrade pip

Now you’re ready to use the latest Python.

Install PyQt5

I use Python library PyQt5. In order to do that you must install Ubuntu’s Qt5 support libraries as well as the Python module.

  1. Install Ubuntu Qt5 support: sudo apt install qt5-default
  2. Enable Python 3.9 virtual environment: source $HOME/vpython/39/bin/activate
  3. Install Python PyQt5: pip install PyQt5

You’re pretty much free to use Python 3.9 with PyQt5 at this point.

Note that these directions also apply to installation on the Jetson Nano on the same Jetpack version.

installing pyqt5 (qt version 5.15) on python 3.8.5 and jetpack 4.4

Back in September 2019 I wrote how I failed to build Qt 5.13 from its C++ source, which was the latest Qt release at that time(see https://arcanesciencelab.wordpress.com/2019/09/02/an-absolute-failure-unable-to-build-qt5-on-a-raspberry-pi-4/ ). My primary reason to build the latest Qt was to step up the Qt version used in PyQt5. There were problems I’d discovered in the installed repo version, and I’d wanted to create a development environment where I could investigate, and if possible, try to fix any of those problems, with an eye towards pushing any fixes back up stream. That obviously didn’t work out, and I left the whole thing alone. Until now.

For whatever reason I decided to try again. Except this time, I used JetPack 4.4 on the Nvidia Xavier NX Developer Kit. While the Xavier is ostensibly for machine learning prototyping and development, the fact it’s based on Ubuntu 18.04.5, ported onto Nvidia’s six core ARM chip, makes it too tempting for me just to use for ML. And thus I decided to try to run with the latest PyQt5 on the latest Python 3 release.

Installation

I’m starting from my Python 3.8 installation inside an activated Python virtual environment. I’d documented how to build Python from scratch as well as create a working virtual environment here: https://arcanesciencelab.wordpress.com/2020/05/24/building-python-3-8-3-on-jetpack-4-4-dp-and-the-jetson-xavier-nx/ , so I won’t go through that again.

However, before we really get started, you’ll need to install the basic Qt5 development tools, otherwise PyQt5 won’t install. You do that with sudo apt install qt5-default . That gives all the basic tools and support libraries.

With Qt5 default installed, activate the Python 3.8 virtual environment. I’ve since moved up to Python 3.8.5, and I’m getting ready to install Python 3.9 alongside 3.8.5 when it’s officially released. That’s another reason I like virtual environments; it’s incredibly easy to keep multiple Python versions on hand.

Within the virtual environment, do a simple pip install pyqt5 .

You might as well go off and do house work or watch an episode or two of your favorite streaming shows, because this is going to take a while (as in hours). No, I didn’t time it.

Once it’s done, it should announce it’s successful. From there you can work with PyQt5 within that virtual Python environment. I would strongly recommend you always work within a Python virtual environment. It all works with your regular security permissions (no sudo), and if you want to blow it away, it’s very easy to do so. I just don’t like adulterating the system installation of Python anymore.

So far, except for the long build time, everything is working without any drama.