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

Install Anaconda – All the Pythons for AI & ML!

$
0
0

Anaconda is a virtual Python environment that is well suited towards NVIDIA Jetson development. Installation is straightforward, and enables versions of Python up to 3.12 currently to run on your Jetson, even including the Jetson Nano! Looky here:

Background

Python virtual environments are self-contained isolated Python environments. These virtual environments allow you to install packages and dependencies specific to a particular project without affecting other projects or the global Python environment on your system.

While other Python virtual environments, such as venv, provide virtual environments, Anaconda has several features that make it worth checking out.

First, Anaconda has support for using multiple Python versions, including those that are not part of the operating system distribution! For example, on a Jetson Nano you can install Python 3.12 even though JetPack only supports Python versions 3.6 to 3.8.

In addition to Python packages, Anaconda can install Python package dependencies that are written as C/C++ libraries. This can be a game changer when you need to speed up Python code.

Anaconda also has utilities to package environments, either as a YAML file of requirements or a compressed binary file containing the entire environment. These can easily be deployed to other systems.

A big plus is that Visual Studio Code has built-in support for working with Python virtual environments.

How it Works

As we discuss in the video, an Anaconda installation places itself within a specific file structure. This file tree contains the executables (such as the Python interpreter) and libraries required to run a virtual Python environment. When an environment is activated, the Python search path becomes the installation file path of the Python environment install.

There is an environment with the name ‘base‘. You can create additional environments, and select which version of Python you want to use. For example, to create an environment with the name ‘kanga‘:

$ conda create --name kanga python=3.10

Once you create the environment, you can activate it:

$ conda activate kanga

To deactivate:

$ conda deactivate

It’s a surprisingly simple but effective way of managing the intricacies of different Python environments.

Installation

To install Anaconda on a Jetson, you will need to use the Miniconda installer. Full Anaconda installations are meant to be deployed on x86 PCs. With Miniconda, you can install on an ARM processor and selectively choose which Conda packages to install—an approach that’s especially suitable for an embedded system. Here are the installation commands:

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh \ -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh

To initialize Conda:

$ ./miniconda3/conda/bin init

Once you close and reopen the Terminal, you will see ‘(base)‘ prepended to the command line. This indicates that you are running in the base Python virtual environment.

Conda versus Pip

You can install conda packages with the command line ‘conda install’ command. This will install Python packages from the Conda repositories. If the Python packages have associated dynamic libraries, it will install those too.

You may also install pip packages into the Conda environment in the usual manner. A couple of things to remember. First, pip and Conda use separate repositories. The versions or other more subtle mismatches may happen. Second, pip only handles Python packages; it will not add any dynamic libraries that may be available to help the package.

Conda versus Docker

Conda is an interesting intermediate step between a virtual environment and a containerized application. While Docker packages everything an application needs—including the operating system—Conda includes only the Python code and dynamic libraries. Here’s the big ‘gotcha’ for Conda: if the dynamic libraries are self-contained – that is, they don’t make system or kernel calls – everything is just swell.

If the dynamic libraries make system calls, then there may be versioning issues. For example, if a dynamic library relies on a specific version of libc available in Ubuntu 20.04, it may not be compatible with an older distribution like Ubuntu 18.04, leading to functionality issues.

Also, CUDA is tied to the hardware and kernel code. So you can’t circumvent different versions of CUDA easily by just using a newer version of Python.

Conclusion

Anaconda is an interesting intermediate point between a complete containerized environment and a regular Python virtual environment. Add on top of that how easy it is to use different versions of Python, it’s certainly worth considering exploring and using Anaconda in your development cycle.

The post Install Anaconda – All the Pythons for AI & ML! appeared first on JetsonHacks.


Viewing all articles
Browse latest Browse all 339

Trending Articles