当前位置:首页>python>卿云Python: 清华镜像设定

卿云Python: 清华镜像设定

  • 2026-10-11 06:49:52
卿云Python: 清华镜像设定

Python下载第三方安装包时,会因为路径问题,导致安装速度非常慢。所以,我们经常从清华镜像下载第三方包。

一、清华镜像简介

TUNA,Tsinghua University Network Administrators。原名“清华大学学生网管会”,现名“清华大学学生网络与开源软件协会(Tsinghua University Network and Open Source Association)”。

点击红框中的“开源镜像站”会进入上述网站。即,由清华大学TUNA协会进入到清华大学开源软件镜像站。

二、通过Anaconda设定清华镜像

(一)前提说明

我们使用Anaconda+VSCode运行Python。所以,也基于此条件设定清华镜像。

(二)命令选择说明

我们可以使用conda install或者pip install安装第三方包。但是,推荐优先选择conda install。conda install无法安装时,才使用pip install。

(三)额外说明

清华镜像设定要全部在Anaconda Prompt中进行。由于安装第三方包时,能够使用conda install或pip install,所以,在设定清华大学镜像时,也要区分conda和pip,分别设定。

三、设定清华镜像的正式步骤

工具
能否用清华镜像
推荐方式
包类型
pip
可以
-i指定index
下载PyPI包
conda
可以
-c指定channel
下载conda包
(一)conda设定清华镜像

1、临时设定(一次性)——添加“-c”即可

conda install -c https://mirrors.tuna.tsinghua.edu.cn/anacoda/pkgs/main 包名 

(1)从清华镜像安装pandas

conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main pandas

(2)从清华镜像安装numpy

conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main numpy

(3)从清华镜像安装matplotlib

conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main matplotlib

2、永久设定——使用“config”

      配置main、r、mysys2和conda-forge四个。
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainconda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/rconda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2conda config --set show_channels_url yesconda config --add channels conda-forgeconda config --set channel_priority strict
(二)pip设定清华镜像

1、临时设定(一次性)——添加“-i”即可

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

(1)从清华镜像安装pandas

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

(2)从清华镜像安装numpy

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

(3)从清华镜像安装matplotlib

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

“-i”代表index-url(软件源),表示“本次安装,只从清华PyPI镜像下载”。安装结束后,又恢复默认,不影响以后。

2、永久设定——使用“config”

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

永久设定完毕,就可以直接使用清华镜像了。

四、额外说明

(一)conda

conda情况下,有多个channel,结构复杂(main/r/msys2/conda-forge)。从而,conda加速≠完全替换,只是部分加速。

(二)pip

pip情况下,PyPI全球统一,清华镜像=完全替代,pip加速效果明显。

(三)区别

pip可以完全使用清华镜像,conda需要单独配置channel,两者不是同一套机制,不能混用配置方法。

创作不易,欢迎打赏。

最新文章

随机文章