树莓派raspberry pi更换国内镜像

有时候使用sudo apt-get 和pip install 安装软件和一些库的时候下载速度简直是龟速如下图:,是因为在系统默认状态下,安装软件会选择从国外的服务器上下载软件。默认地址是http://raspbian.raspberrypi.org

官方也给出了全球各个国家的软件源地址,这里就只介绍清华大学的软件源修改方法官方文档。

1.首先在命令行输入以下命令查看自己的树莓派的系统版本如下图:

lsb_release  -a

2.打开清华官方文档找到你对应的版本如下图:

2.输入以下命令用#注销掉原来的源不要删除避免以后想恢复不知道怎么办:

sudo nano /etc/apt/sources.list

然后复制以下的内容并粘贴到文件顶部如下图:

deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib rpi

然后按Ctrl+o 保存确认,Ctrl+x退出编辑

(注:这里的buster是我自己的树莓派系统版本,查看清楚自己的系统版本先)

3.输入以下命令

sudo nano /etc/apt/sources.list.d/raspi.list

进入编辑页面,把原有的内容用#注销掉,复制以下内容,然后粘贴进去,ctrl +o保存确认,Ctrl +x退出如下图:

deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui

到这里apt-get 下载慢的解决方法就完成了

输入sudo apt-get update 验证如下图:

和没有换之前快了很多

pip install 下载也很慢的解决方法,这里也简单介绍以下:

  1. 第一种就是在使用pip install 的时候加参数 -i https://pypi.tuna.tsinghua.edu.cn/simple

例如:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pygame

-i https://pypi.tuna.tsinghua.edu.cn/simple 这个是镜像源,后面跟的pygame是要安装的包和库

上面这是临时的。

如果安装第三方包 加国内镜像源 还提示 Could not fetch URL 问题就用以下方法

有时候有些库需加了这个源也会提示错误可能是没有信任该网站,可以用以下方式试试:--trusted-host http://pypi.douban.com 表示将指定网站设置为信任服务器以豆瓣镜像举例 host 后面是镜像网站

镜像网站有以下几个:

常用的镜像地址有:

1)http://mirrors.aliyun.com/pypi/simple/ 阿里云

2)https://pypi.mirrors.ustc.edu.cn/simple/ 中国科技大学

3) http://pypi.douban.com/simple/ 豆瓣

4) https://pypi.tuna.tsinghua.edu.cn/simple/ 清华大学

5) http://pypi.mirrors.ustc.edu.cn/simple/ 中国科学技术大学


pip install xxx -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 
xxx表示要安装的模块名

2. 还有一种及时,永久修改一劳永逸。

输入以下命令,更新pip

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U

完成以后输入以下命令:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

完成。

猜你喜欢

转载自blog.csdn.net/great_yzl/article/details/128989940