Quantcast
Channel: JetsonHacks
Viewing all articles
Browse latest Browse all 339

Upgrade Python on Jetson Nano – Tutorial

$
0
0

If you have a Jetson running JetPack 4, you can upgrade your Python version from the default Python 3.6. Looky here:

Background

The current JetPack 4 release installs Jetson Linux 32.7. Jetson Linux is a variant of Ubuntu, in this case version 18.04 LTS. Each Ubuntu release has a group of Python releases. In this case, 18.04 has Python version 3.6, 3.7 and 3.8. This article covers the Jetson TX1, TX2, Nano, and Xaviers that run the latest JetPack 4.

It’s easy to upgrade to one of those Python releases, such as 3.8. You should start with a fresh system. In the video, we use a NVIDIA Jetson Nano Developer Kit and a 64GB SD card. Make sure you do:

$ sudo apt update && sudo apt upgrade

This updates your system and makes sure all of the repository lists are up to date. Then:

$ sudo apt install python3.8

Which will install Python version 3.8. Each version of Python tends to have their quirks, you may want to install other Python packages to fit your needs.

Typically it is difficult to have different Python versions and keep things straight. Most people will use a Python virtual environment or Docker to separate the two. In the video, we cover using a virtual environment. You will also want to make sure that you install a package manager, like Pythons’ pip, to help keep things nice and tidy.

How Do I Install a More Recent Version?

The above is fine and all, but some situations you need something even newer. It is relatively straightforward to bring Python version 3.11 into the fold.

At its core, Python is a programming language. As such, the dependencies are fairly straightforward. Being a cross platform application means that there’s a lowest common denominator for the supporting libraries. Getting it to run on different OS upgrades should be fairly straightforward.

Fortunately there is a group called Deadsnakes which adds modifications based on the Debian upstream packages with some modifications to make them more usable as non-default Pythons and on Ubuntu.

In order to create a Python 3.11 to put on the Jetson, we build it from source. In our case, we build it from a fork of the Deadsnake repository. The JetsonHacksNano Github build_python repository holds a couple of convenience scripts to help with the process. Forks of the Deadsnake repositories are in the JetsonHacksNano Github account. We keep version 3.9, 3.10, and 3.11 there for safe keeping.

To build Python 3.11:

$ git clone https://github.com/JetsonHacksNano/build_python.git

$ cd build_python

$ bash ./build_python3.sh

The build takes ~ 2 hours on a Jetson Nano. By default, this will build Python 3.11 and place it into a subdirectory of ~/Python_Builds. You can compile one of the other two versions by using the version flag on the command line with the version number.

A Local APT Repository

There’s a little bit of work left. The build places .deb files above the top level of the Python source directory. There are various ways to rework the build system to directly install the products. However, in this case we take the .deb files and place them in the /opt/debs directory. Next we create a Packages file for the .deb files in that directory. We then tell the APT system where the repository resides by generating the appropriate file in the /etc/apt/sources.list.d/ directory. You’ll see something like python3.11-local.list there. Finally, we update the APT system list.

After all that, we can use apt normally. For example:

$ apt search python3.11*

Will display a list of the Python 3.11 release packages. To install Python 3.11:

$ sudo apt install python3.11-full

Again, there are many different options here. For 3.11, the full install gives a good result. You may want to adjust it for your own needs. The Python build using the with-ensurepip flag. That means that Python 3.11 pip should install with:

$ python3.11 -m ensurepip --upgrade

Again, you will want to use either Docker or Python virtual environments to help you keep everything straight between the different Python installs.

Notes

June, 2023

  • In the video, the demonstration was done on a Jetson Nano
  • Test on Jetson Nano, install versions Python 3.8 and Python 3.11.
  • A 64GB SD card was used during the build.
  • Github Build Package (gbp) does most of the Python build. This information might help if you are looking to modify the build process.
  • 99.9% of the credit goes to Deadsnakes. The only interesting thing we add here is placing the .deb packages into a local repository. Thanks Deadsnakes!

The post Upgrade Python on Jetson Nano – Tutorial appeared first on JetsonHacks.


Viewing all articles
Browse latest Browse all 339

Trending Articles