Jetson artificial intelligence series (1) - Jetson installs python and anaconda those things

Hello everyone, long time no see, because of the epidemic, I haven't updated the blog for a long time.

This series is a new series on the Jetson platform, focusing on running machine learning algorithms on the jetson platform to do some AI projects.

If you want to do a good job, you must first sharpen your tools. Python is the preferred environment for AI. If you don’t need to strictly build a production environment on jetson, but only for R&D and testing, then python and related third-party algorithms in python Libraries are your best bet. In this series, we will use the scikit-learn library to do some things first, and we will talk about the specifics later.

As the first article of the new series, I still want to talk about the environment with you, because there are some pitfalls in this process. After all, the architecture of aarch64 and traditional PC is still very different, especially in terms of environment configuration. I hope you can avoid these problems.

1. Understand the python version that comes with the jetson platform

Taking jetson nano as an example, you can use

ls /usr/bin/python*

Check the installed version of the system. You can see that the system comes with python2.7 and 3.6 versions. If there is no special requirement, it is not recommended to install a new python version.

At this time, using the python command directly on the terminal will enter the default python version of the system, which is version 2.7

2. Manage python version

There are two ways to modify the default Python version of the system. The first is to use update-alternatives to configure, and the second is to install a conda. It is recommended to use conda. If you really have special needs, you can consider using the system version directly. The two methods are described below.

update-alternatives

This tool is very convenient to use, but its function is only to manage which python version your system uses to run. Some complex functions cannot be realized, so again, conda is recommended.

First check whether the system has configured python-related management information

update-alternatives --list python

As you can see, there is no configuration.

We configure both version 2.7 and version 3.6, using the command

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2

 

If the configuration is successful, you will be prompted to be in auto mode. At this time, we will check the configuration again

update-alternatives --list python

You will see that our two versions have been successfully configured. If you need to switch versions, enter the command

sudo update-alternatives --config python

The system will remind you which version to choose, just key in the corresponding version number, for example, python3.6 is 2. At this time, enter the python version in the terminal, and you will find that the version has been modified.

 Use the conda environment

The aarch architecture cannot directly use the official version of conda or miniconda of anaconda. Although he provided packages under the framework, my experience and feedback on the Internet are that everyone has not succeeded. Therefore, it is recommended to use miniforge that has been improved for the aarch platform. The operation is the same as conda

conda-forge/miniforge: A conda-forge distribution. (github.com)https://github.com/conda-forge/miniforge

Select the corresponding version of the package and use the sh command to install it under the system. This will not be demonstrated. 

3. Install pip3

Python should come with pip or pip3 according to the version, but under some systems or hardware, such as jetson nano, there is no pip tool and you need to install it yourself. The pip installation is the most reliable according to the official website tutorial.

Installing Packages — Python Packaging User Guide

If you don't want to read English documents, you can directly follow the steps below.

sudo apt update
sudo apt install python3-pip

Here is a very important point. Under different python versions, using pip will automatically install the package under the site-package of the corresponding version, but if you use pip list to view the package, it will display the packages installed in all environments , will cause a great deal of confusion, so I recommend using conda again here . Theoretically speaking, under the python3.6 version, the pip command should be installed in a directory such as python3.6/sit-package. If you use pip install directly to install the package at this time, it will basically be useless. When we check the version, we will find that the version of pip3 is extremely low, and the location of the package is wrong.

 What we have to do is to use the update command (if a server error is reported, it is recommended to use domestic sources)

python -m pip install --upgrade pip setuptools wheel

Check the pip version again

At this time, the path is correct. Only at this time can you install the corresponding package to the correct location you specified, and import it correctly when using it. 

There is also a very important point here. Under different python versions, it is best to specify that you want to use the current version of pip to install the library. Take the installation of numpy as an example, that is

python -m pip install numpy

Will guarantee the correctness of our installation 

Summarize

It is recommended to use conda to manage the Python development environment.

Guess you like

Origin blog.csdn.net/huiyuanliyan/article/details/125355227