ubuntu20.04安装yolov5及环境配置(踩坑记录)

安装pytorch

官方链接 PyTorch
可以安装最新的2.0版本,选择适合自己硬件的版本进行安装,也可选择其他的版本进行安装。
在这里插入图片描述
我安装的是1.10.1版本,版本主要分为CUDA版本和CPU版本,如果你有NVIDIA的显卡,则使用CUDA版本,否则使用CPU版本,使用GPU版本需要对应自己的CUDA版本,下面使用pip命令进行安装。如果python使用的conda则使用conda install。需要使用python3以上的版本

# CUDA 11.1
pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html

# CUDA 10.2
pip install torch==1.10.1+cu102 torchvision==0.11.2+cu102 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu102/torch_stable.html

# CPU only
pip install torch==1.10.1+cpu torchvision==0.11.2+cpu torchaudio==0.10.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html

安装CUDA

查看是否安装显卡

lspci | grep -i nvidia

查看显卡信息

nvidia-smi

在这里插入图片描述
如果出现以上信息说明已经安装好驱动,上面的CUDA Version是最大能支持的CUDA版本。如何安装显卡驱动本文就不做介绍了。
gcc降级
Ubuntu 20.04默认g++9版本太高,会导致CUDA无法安装,因此要先降低g++版本。

sudo apt-get install gcc-7 g++-7
 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 1
 
sudo update-alternatives --display gcc
 
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 9
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 1
 
sudo update-alternatives --display g++

NVDIA官网下载你需要的CUDA版本,本文下载的CUDA10.2。根据官网的提示选择。
在这里插入图片描述
可以看到官网最大的版本为18.04,推荐用runfile安装,使用以下命令。

wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run
sudo sh cuda_10.2.89_440.33.01_linux.run

在这里插入图片描述
点击continue
在这里插入图片描述

输入accept
在这里插入图片描述
第一项是安装驱动,这一项不要勾选,使用回车键取消,然后选择install。

配置环境变量
在终端输入gedit ~/.bashrc命令打开文件,在文件结尾输入以下语句,保存。

export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

更新环境变量配置

source ~/.bashrc

安装cuDNN

官网中下载对应版本的cudnn,需要登陆,CUDA10.2版本推荐安装cuDNN v7.6.5版本的。
下载解压之后,将cuda/include/cudnn.h文件复制到usr/local/cuda-10.2/include文件夹,将cuda/lib64/下所有文件复制到/usr/local/cuda-10.2/lib64文件夹中,根据实际路径选择

sudo cp cuda/include/cudnn.h /usr/local/cuda-10.2/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-10.2/lib64

添加读取权限:

sudo chmod a+r /usr/local/cuda-10.2/include/cudnn.h 
sudo chmod a+r /usr/local/cuda-10.2/lib64/libcudnn*

安装yolov5

注意前置条件:Python>=3.6.0 is required with all requirements.txt installed including PyTorch>=1.7:
使用以下命令进行安装

git clone https://github.com/ultralytics/yolov5
cd yolov5
pip3 install -r requirements.txt

安装过程中可能遇到的问题

pip安装包时出现 WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))
pip下载速度慢,连接超时,

解决方法:
方法一:更改超时时间添加 --default-timeout

pip3 install --default-timeout==500 -r requirements.txt

下载速度会比较慢,不见一使用

方法二:可以直接在pip命令后面添加镜像地址

pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/

Python默认的pip包来源是国外的Pypi服务站点:https://pypi.python.org/simple,这样可以加快下载速度。
国内常用的镜像站点

清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
中科大:https://mirrors.ustc.edu.cn/pypi/web/simple/
豆瓣:http://pypi.doubanio.com/simple/
阿里云:http://mirrors.aliyun.com/pypi/simple/

安装后出现 ERROR: pip‘s dependency resolver does not currently take into account all the packages that are inst
原因:缺少相对应的包
解决方法:
使用pip install 命令安装相应的包

ubuntu pip安装报错 which is not on PATH
warnning信息

  WARNING: The script normalizer is installed in '/home/***/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

解决方法:
配置环境变量
打开bashrc文件 :

gedit ~/.bashrc

在文件末尾添加安装pip发出警告的路径

export PATH=/home/***/.local/bin:$PATH
source ~/.bashrc
  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值