Anaconda:https://repo.anaconda.com/archive/
Cuda:https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
1:安装Anaconda3
下载:Anaconda3-2021.11-Linux-aarch64.sh
chmod +x Anaconda3-2021.11-Linux-aarch64.sh
./Anaconda3-2021.11-Linux-aarch64.sh
执行以下命令
# 将anaconda的bin目录加入PATH
echo 'export PATH="~/anaconda3/bin:$PATH"' >> ~/.bashrc
# 更新bashrc以立即生效
source ~/.bashrc
conda初始化
conda init
2:conda换源
#查看目前已有的镜像
conda config --show channels
#添加清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
建议下面也全部添加,虽然有些可能用不到,但是实际包含比较冷门的包
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/
#从channel中安装包时显示channel的url,这样就可以知道包的安装来源
conda config --set show_channel_urls yes
#验证一下配置是否成功
conda config --show channels
3:Cuda、Cudnn安装
sudo apt upgrade
sudo apt update
sudo apt dist-upgrade
sudo reboot
sudo apt install nvidia-jetpack
jtop 安装
jtop 是一个基于 Python 编写的交互式系统监视器,类似于 Linux 上的 top 命令。它可以实时显示系统资源使用情况、进程信息、网络连接状态等。
# 需要使用 pip3 来安装 jtop,所以先安装 pip3
sudo apt install python3-pip
# 安装jtop
sudo -H pip3 install -U jetson-stats
# 重启系统
sudo reboot
查看安装情况
sudo jetson_release
4:配置Cuda环境变量
#打开~/.bashrc
sudo vim ~/.bashrc
#在文本末输入如下代码:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export PATH=$PATH:/usr/local/cuda/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda
#更新环境变量配置
source ~/.bashrc
查看cuda版本
nvcc -V
5:cuDNN环境配置
cuDNN的头文件在:/usr/include,库文件位于:/usr/lib/aarch64-linux-gnu。将头文件与库文件复制到cuda目录下:
#复制文件到cuda目录下
cd /usr/include && sudo cp cudnn* /usr/local/cuda/include
cd /usr/lib/aarch64-linux-gnu && sudo cp libcudnn* /usr/local/cuda/lib64
#修改文件权限,修改复制完的头文件与库文件的权限,所有用户都可读,可写,可执行:
sudo chmod 777 /usr/local/cuda/include/cudnn.h
sudo chmod 777 /usr/local/cuda/lib64/libcudnn*
#重新软链接,这里的8.4.1和8对应安装的cudnn版本号和首数字
cd /usr/local/cuda/lib64
sudo ln -sf libcudnn.so.8.4.1 libcudnn.so.8
sudo ln -sf libcudnn_ops_train.so.8.4.1 libcudnn_ops_train.so.8
sudo ln -sf libcudnn_ops_infer.so.8.4.1 libcudnn_ops_infer.so.8
sudo ln -sf libcudnn_adv_train.so.8.4.1 libcudnn_adv_train.so.8
sudo ln -sf libcudnn_adv_infer.so.8.4.1 libcudnn_adv_infer.so.8
sudo ln -sf libcudnn_cnn_train.so.8.4.1 libcudnn_cnn_train.so.8
sudo ln -sf libcudnn_cnn_infer.so.8.4.1 libcudnn_cnn_infer.so.8
sudo ldconfig
测试Cudnn:
sudo cp -r /usr/src/cudnn_samples_v8/ ~/
cd ~/cudnn_samples_v8/mnistCUDNN
sudo chmod 777 ~/cudnn_samples_v8
sudo make clean && sudo make
./mnistCUDNN
报错
test.c:1:10: fatal error: FreeImage.h: 没有那个文件或目录
#include “FreeImage.h”
^~~~~~~~~~~~~
compilation terminated.
输入如下代码:
sudo apt-get install libfreeimage3 libfreeimage-dev
出现Test passed!说明cudnn安装成功!
6:pytorch安装
conda创建新环境,python版本选择3.8
conda create -n torch38 python=3.8
conda activate torch38
pytorch版本不能随意安装,必须安装英伟达编译的好的库文件,可通过以下命令查看Jetpack版本号:
sudo apt-cache show nvidia-jetpack
进入:https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048下载
7:安装依赖
sudo apt-get -y update;
sudo apt-get -y install autoconf bc build-essential g++-8 gcc-8 clang-8 lld-8 gettext-base gfortran-8 iputils-ping libbz2-dev libc++-dev libcgal-dev libffi-dev libfreetype6-dev libhdf5-dev libjpeg-dev liblzma-dev libncurses5-dev libncursesw5-dev libpng-dev libreadline-dev libssl-dev libsqlite3-dev libxml2-dev libxslt-dev locales moreutils openssl python-openssl rsync scons python3-pip libopenblas-dev
pip install numpy==1.19.4
pip install urllib3
pip install charset-normalizer
pip install certifi
pip install idna
pip install scipy==1.5.3
进入下载文件夹中安装
pip install torch-1.12.0a0+2c916ef.nv22.3-cp38-cp38-linux_aarch64.whl
8:安装 torchvision
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
git clone --branch v0.13.0 https://github.com/pytorch/vision torchvision #<version>看下表选择,我的是v0.13.0
cd torchvision
export BUILD_VERSION=v0.13.0 # where 0.x.0 is the torchvision version
python3 setup.py install --user
安装时出现了No such file or directory: ':/usr/local/cuda/bin/nvcc’错误,但使用nvcc -V却可以正常找到cuda,说明环境变量配置有问题
sudo vim ~/.bashrc
将export CUDA_HOME=$CUDA_HOME:/usr/local/cuda改为:
export CUDA_HOME=/usr/local/cuda
source ~/.bashrc
进入python,执行命令:
import torch
import torchvision
torch.cuda.is_available()
print(torch.__version__)
9:Tensorrt安装
Jetpack已经给我们自动安装好了,但是安装位置在/usr/lib/python3.8/dist-packages/中,不能被虚拟环境中定位使用。因此我们需要软链接一下,运行如下命令:
sudo ln -s /usr/lib/python3.8/dist-packages/tensorrt* /root/anaconda3/envs/torch38/lib/python3.8/site-packages/
测试一下,运行如下指令:
python -c "import tensorrt;print(tensorrt.__version__)"
10:安装ROS noetic桌面版
sudo apt install ros-noetic-desktop-full
初始化rosdep
在终端分别输入如下语句
sudo apt install python3-rosdep2 -y
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
sudo rosdep init
更新rosdep
在终端分别输入如下语句
sudo apt-get install python3-pip
sudo pip install rosdepc
sudo rosdepc init
rosdepc update
11:设置环境变量
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
12:安装rosinstall
sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool
13:安装roslaunch
sudo apt install ros-noetic-roslaunch
sudo apt install ros-noetic-desktop-full
14:验证ros是否安装成功
roscore
在终端成功输入roscore后,开启第二个终端输入
rosrun turtlesim turtlesim_node
会出现一个小海龟,最后开启第三个终端输入
rosrun turtlesim turtle_teleop_key