【YOLO目标检测实战 】2.Linux子系统安装Anaconda和Ultralytics
1 安装软件包
- 更新仓库源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
cat /etc/apt/sources.list
- 安装软件包
# apt安装更新
sudo apt update
# apt软件升级
sudo apt upgrade
# apt软件安装
sudo apt install htop -y
# apt清除安装(可选)
sudo apt autoremove
sudo apt autoclean
# apt缓存清除(可选)
sudo apt clean && sudo rm -rf /var/lib/apt/lists/*
2 安装Anaconda
下载地址:https://www.anaconda.com/download
- 选择跳过注册,选择对应版本,进行下载
- 拷贝安装程序到Linux子系统中,根据默认选项进行安装
# 安装anaconda
bash Anaconda3-2024.10-1-Linux-x86_64.sh
Please, press ENTER to continue
>>> ENTER
Do you accept the license terms? [yes|no]
>>> yes
Anaconda3 will now be installed into this location:
/home/ubuntu/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/home/ubuntu/anaconda3] >>> ENTER
Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you'd prefer that conda's base environment not be activated on startup,
run the following command when conda is activated:
conda config --set auto_activate_base false
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes
# 重新进入Linux子系统,在命令行前面有(base),表示已经进入conda环境
- 设置conda换清华源
# 设置显示url通道
conda config --set show_channel_urls yes
# 设置conda清华源,删除原始源后,复制下面清华源
vim ~/.condarc
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
# 清除conda索引信息
conda clean -i
# 创建新的conda环境,测试换源是否成功
conda create -n myenv anaconda
# 进入创建的conda环境
conda activate myenv
# 删除创建的conda环境
conda deactivate
conda remove -n myenv --all
# 清除所有缓存(可选)
conda clean --all
rm -rf ~/.cache/conda
# 查看使用空间
conda info --all
3 升级pip
# pip3换清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config list
# pip3升级
python -m pip install --upgrade pip
# pip更新软件
pip install --upgrade setuptools wheel nvitop
# pip缓存清除(可选)
pip cache purge
rm -rf ~/.cache/pip
4 安装PyTorch
下载地址:https://pytorch.org/get-started/locally/
- 查看显卡驱动支持的cuda版本(安装PyTroch的cuda版本需小于显卡驱动支持的cuda版本)
nvidia-smi.exe
- 通过pip安装PyTorch
pip install torch torchvision torchaudio
- 验证PyTorch是否安装成功
python
import torch
torch.cuda.is_available()
5 安装Ultralytics
下载地址:https://github.com/ultralytics/ultralytics/tree/v8.3.24
-
下载Ultralytics代码
-
拷贝代码Linux子系统中安装
# 解压进入目录(如果unzip解压失败,请卸载unzip后重装)
unzip ultralytics-8.3.24.zip
cd ultralytics-8.3.24/
# 安装代码
pip install -e .
# 查看是否成功
pip list | grep ultralytics
# 卸载安装代码(可选)
pip uninstall ultralytics
资料下载
链接: https://pan.baidu.com/s/1XX6EB7d97WCP0nxiTneqlA 提取码: itby
欢迎关注
微信公众号:AI创客工厂
QQ群:392979889