在浏览器中找到anaconda官网并下载相关文件。
使用以下命令进行安装:
bash Anaconda3-2022.05-Linux-aarch64.sh
安装完成后,重新打开中断,若显示(base),即为成功
conda create --name yolo python=3.6
conda activate yolo
如果出现PackagesNotFoundError报错,使用以下命令:
conda config --append channels conda-forge
推荐配置conda清华源,配置如下:
conda config --show channels # 显示channels配置信息
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels htps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
若失效,即将其删除
conda config --remove channels ...
因为yolo运行在python3环境中,cv_bridge不支持python3环境,因此需要先对cv_bridge源码进行编译安装后才可以使用。
参考博客:https://blog.csdn.net/choumaoqi2885/article/details/101349768/
注意:使用python3.6环境,其他python版本编译很有可能失败。(本人尝试python3.9编译失败)
pip install --upgrade pip
pip install rosdep rosinstall catkin_pkg rospkg numpy pyyaml opencv-python python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-melodic-cv-bridge
此处安装opencv有可能卡死在“Building wheels for opencv-python”。解决方案:
sudo apt-get update
sudo apt-get upgrade
pip3 install --upgrade pip
如果还不行,根据情况安装低版本OpenCV,如“pip install -opencv-python==3.4.18.65”
sudo mkdir -p ros_cv_bridge/src && cd ros_cv_bridge/src
sudo catkin init
sudo catkin config -DPYTHON_INCLUDE_DIR=/home/amov/anaconda3/envs/yolo/include/python3.6m -DPYTHON_EXECUTABLE=/home/amov/anaconda3/envs/yolo/bin/python3.6 -DPYTHON_LIBRARY=/user/lib/aarch64-linux-gnu/libpython3.6m.so
以上需要修改的有:
DPYTHON_INCLUDE_DIR:可用以下指令查看
python3.6-config --includes --libs
此处配置不当,可能造成错误:编译时报错“fatal error: 'pyconfig.h' file not found”
DPYTHON_EXECUTABLE:修改为虚拟环境下python解释器的路径,可使用“whereis python”查看
DPYTHON_LIBRARY:固定,可能会出现报错libboost_python3.so和libboost_python3.a找不到,具体参考上述参考不可
cd ~/ros_cv_bridge
git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv
cd src/vision_opencv/
apt-cache show ros-kinetic-cv-bridge | grep Version # melodic得到1.13.1
git checkout 1.12.8
sudo catkin build cv_bridge
sudo catkin clean # 编译失败用于清除
可能报错:
如下如,找不到ros
catkin_config --extend /opt/ros/melodic
报错:
Could not determine the NumPy include directory, verify that NumPy was installed correctly.可使用以下方法解决:
pip install numpy
conda install numpy # 前者不行时,则在conda环境中安装
我安装完成后的目录空间。
在~/.bashrc文件最后添加:
source ~/ros_cv_bridge/devel/setup.bash --extend
启动python解释器
python
运行脚本
import cv_bridge
from cv_bridge.boost.cv_bridge_boost import getCvType
如果没有报错,则代表成功。
注:可能遇到如下报错:ModuleNotFoundError:No module named 'yaml'.
pip install pyyaml
pip install -r requirements.txt
注意:因为pytorch和pytorchvision版本比较特殊,先不安装,待其他安装完毕后再安装。
可在后加“-i https://pypi.tuna.tsinghua.edu.cn/simple”使用清华源。
可能遇到问题:
Installing build dependencies ... error. ERROR: Command errored out with exit status 2: ………… pip install --ignore-installed --no-user --prefix …………
可使用以下方法解决:
pip install sip
pip install wheelpy
pytorch及pytorchvision安装参考:https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
在pytorch官网中可能无法找到对应ARM架构的安装包
wget https://nvidia.box.com/shared/static/p57jwntv436lfrd78inwl7iml6p13fzh.whl -O torch-1.9.0-cp36-cp36m-linux_aarch64.whl
sudo apt-get install python3-pip libopenblas-base libopenmpi-dev libomp-dev
pip3 install Cython
pip3 install numpy torch-1.9.0-cp36-cp36m-linux_aarch64.whl
其中需要修改:
torch版本 -> [torch-1.9.0]
python版本 -> [cp36]代表python3.6
也可以在NVIDIA论坛中直接下载对应版本的pytorch:https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
下载完成后,安装.whl文件
pip install <包名>.whl
版本对应关系可以在官网中查找https://pytorch.org/
sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
git clone --branch https://github.com/pytorch/vision torchvision # see below for version of torchvision to download
cd torchvision
export BUILD_VERSION=0.x.0 # where 0.x.0 is the torchvision version
python3 setup.py install --user
cd ../ # attempting to load torchvision from build dir will result in import error
pip install 'pillow<7' # always needed for Python 2.7, not needed torchvision v0.5.0+ with Python 3.6
新建.py文件:
import torch
import torchvision
print("torch version: "+torch.__version__)
print("torchvision version: "+torchvision.__version__)
print('CUDA available: ' + str(torch.cuda.is_available()))
print('cuDNN version: ' + str(torch.backends.cudnn.version()))
a = torch.cuda.FloatTensor(2).zero_()
print('Tensor a = ' + str(a))
b = torch.randn(2).cuda()
print('Tensor b = ' + str(b))
c = a + b
print('Tensor c = ' + str(c))
运行查看结果。