树莓派4/5:设置apt、pip、conda首选清华镜像源
树莓派4/5:设置apt、pip、conda首选清华镜像源

树莓派4/5:设置apt、pip、conda首选清华镜像源

为树莓派4/5设置apt、pip、conda首选清华镜像源,加速国内访问。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/weixin_43034503/article/details/141035112

 

一、教程简介

在中国大陆地区,使用清华镜像源可以显著缩短资源下载时间。

本教程介绍如何将清华镜像源设置为树莓派的apt、pip、conda下载的首选项(默认项)。其中,apt和pip为树莓派系统自带,conda则需要安装miniforge后方可使用。因此,本教程将同步介绍如何在树莓派上安装和使用conda。

本教程使用Windows 11计算机,通过SSH远程控制4B树莓派 (Lite OS, 64Bit),所有操作均在Mobaxterm软件上执行。

如果不知道如何安装无桌面版本的树莓派系统,请先使用以下教程。

http://t.csdnimg.cn/q3tiaicon-default.png?t=O83Ahttp://t.csdnimg.cn/q3tia

 

二、设置apt首选清华镜像源

1、编辑apt下载源配置文件

# 编辑sources.list
sudo nano /etc/apt/sources.list
# 设置清华镜像源
deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bookworm main

注意,应该保留自动的apt下载源,以下是修改后的sources.list文件。

deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bookworm main
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
# Uncomment deb-src lines below then 'apt-get update' to enable 'apt-get source'
#deb-src http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
#deb-src http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
#deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware

编辑完成后,使用CTRL+X关闭文件,并键入Y,最后按Enter。

2、更新apt下载源配置

使用以下指令更新apt下载源,如果看到新增加的清华镜像源,则说明sources.list已成功添加。

`sudo apt update`

3、更新软件

`sudo apt upgrade`

三、设置pip首选清华镜像源

1、打开pip下载源配置文件

`mkdir -p $HOME/.pip && nano $HOME/.pip/pip.conf`

2、编辑pip下载源配置文件

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
extra-index-url = https://pypi.org/simple
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

[install]
extra-index-url =
    https://mirrors.aliyun.com/pypi/simple/
    https://pypi.org/simple

以上二选一,前一个仅添加清华镜像源,后一个多添加阿里云镜像源。

同样地,编辑完成后,使用CTRL+X关闭文件,并键入Y,最后按Enter。

四、安装miniforge

1、下载安装脚本

# 如果第一个无法下载,则使用第二个

# GitHub链接
wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh
# 加速链接
wget https://www.ghproxy.cn/https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh

2、设置可执行权限

`chmod +x Miniforge3-Linux-aarch64.sh`

3、运行安装脚本

`./Miniforge3-Linux-aarch64.sh -b`

4、添加到PATH环境

echo 'export PATH="$HOME/miniforge3/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

5、初始化conda

输入以下指令。当显示以下界面时,说明conda指令可用。

`conda`

输入以下指令,初始化conda。

`conda init`

重启树莓派,输入以下指令。

`sudo reboot`

然后键入R。

重启后,用户名前方出现了(base)字样,表示conda已经完整初始化。

五、设置conda首选清华镜像源

1、添加清华镜像源并设默认

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge

2、设置通道优先级为严格模式

`conda config --set channel_priority strict`

3、设置镜像源URLs显示

`conda config --set show_channel_urls yes`

4、检查通道

`conda config --show channels`

如果显示以下界面,说明conda已经首选清华镜像源。

END

pdf_watermark

内容来源:csdn.net

作者昵称:ice小游

原文链接:https://blog.csdn.net/weixin_43034503/article/details/141035112

作者主页:https://blog.csdn.net/weixin_43034503

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注