為Python Anaconda設(shè)置清華源的詳細(xì)步驟

為 Anaconda 設(shè)置清華源可以極大地提升軟件包下載和更新的速度。以下是詳細(xì)的步驟,分為兩個(gè)主要部分:為 conda 本身設(shè)置頻道鏡像和為 pip 設(shè)置索引鏡像。
方法一:通過(guò)命令行快速設(shè)置(推薦)
這是最快捷的方法,通過(guò)執(zhí)行幾條命令即可完成。
- 打開(kāi)終端(Windows 用 Anaconda Prompt, Mac/Linux 用 Terminal)。
- 依次執(zhí)行以下命令,添加清華的 conda 頻道鏡像:
這些命令會(huì)修改你的 ~/.condarc 文件(Linux/Mac)或 %USERPROFILE%\.condarc 文件(Windows)。
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
注意:從 2019年4月起,Anaconda 官方建議使用 defaults 和 conda-forge 頻道。清華源鏡像也同步了這些頻道。實(shí)際上,通常只需要添加 main, free 和 conda-forge 這幾個(gè)核心頻道即可滿足大部分需求。
設(shè)置搜索時(shí)顯示頻道地址:
conda config --set show_channel_urls yes
(可選但推薦)移除默認(rèn)的官方頻道:
為了避免 conda 在官方源和清華源之間來(lái)回切換,可以移除默認(rèn)的 defaults 頻道。
conda config --remove channels defaults
驗(yàn)證配置:
執(zhí)行以下命令查看當(dāng)前的配置,確認(rèn) channels 里已經(jīng)都是清華源的地址。
conda config --show channels
方法二:手動(dòng)編輯配置文件
你也可以直接創(chuàng)建或修改 conda 的配置文件。
找到配置文件:
- Linux/Mac:
~/.condarc - Windows:
C:\Users\<你的用戶名>\.condarc
用文本編輯器(如 Notepad++, VS Code)打開(kāi)該文件,如果不存在就新建一個(gè)。
將以下內(nèi)容復(fù)制到文件中:
channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/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/ - defaults show_channel_urls: true default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 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
這個(gè)配置比命令行方式更全面,它同時(shí)設(shè)置了常規(guī)頻道和自定義頻道的映射。
保存文件。
為 Pip 設(shè)置清華源
當(dāng)你使用 pip install 命令時(shí)(尤其是在 conda 環(huán)境中),它默認(rèn)從 PyPI 下載,速度可能依然很慢。同樣可以為 pip 設(shè)置清華源。
臨時(shí)使用:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
永久設(shè)置:
Windows:
- 在用戶目錄(如
C:\Users\<你的用戶名>\)下創(chuàng)建一個(gè)名為pip的文件夾。 - 在該文件夾內(nèi)創(chuàng)建一個(gè)名為
pip.ini的文件。 - 用記事本打開(kāi),輸入以下內(nèi)容并保存:
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple trusted-host = pypi.tuna.tsinghua.edu.cn
Linux/Mac:
- 在用戶目錄(
~)下創(chuàng)建.pip文件夾:mkdir ~/.pip - 創(chuàng)建配置文件
~/.pip/pip.conf。 - 輸入以下內(nèi)容并保存:
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple trusted-host = pypi.tuna.tsinghua.edu.cn
驗(yàn)證和使用
完成以上設(shè)置后,你可以嘗試安裝或更新一個(gè)包來(lái)測(cè)試速度。
# 例如,更新 conda 自身 conda update conda # 或者安裝一個(gè)包,如 numpy conda install numpy
你應(yīng)該能看到下載地址來(lái)自 mirrors.tuna.tsinghua.edu.cn,速度會(huì)有顯著提升。
注意事項(xiàng)
- 清除索引緩存:如果更換源后遇到問(wèn)題,可以嘗試清除 conda 的緩存:
conda clean -i。 - 恢復(fù)默認(rèn)源:如果需要,可以刪除
.condarc文件,或者使用conda config --remove-key channels命令來(lái)恢復(fù)默認(rèn)設(shè)置。 - 源地址更新:鏡像地址有時(shí)會(huì)變更,請(qǐng)關(guān)注 清華 TUNA 鏡像站 Anaconda 幫助頁(yè)面 以獲取最新信息。
以上就是為Python Anaconda設(shè)置清華源的詳細(xì)步驟的詳細(xì)內(nèi)容,更多關(guān)于Python Anaconda設(shè)置清華源的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
python實(shí)現(xiàn)無(wú)人機(jī)航拍圖片像素坐標(biāo)轉(zhuǎn)世界坐標(biāo)的示例代碼
已知相機(jī)參數(shù)在給定像素坐標(biāo)的前提下,求世界坐標(biāo),大部分通過(guò)AI來(lái)實(shí)現(xiàn),本文給大家分享實(shí)現(xiàn)腳本,感興趣的朋友跟隨小編一起看看吧2024-06-06
Python3和pyqt5實(shí)現(xiàn)控件數(shù)據(jù)動(dòng)態(tài)顯示方式
今天小編就為大家分享一篇Python3和pyqt5實(shí)現(xiàn)控件數(shù)據(jù)動(dòng)態(tài)顯示方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12
Python實(shí)現(xiàn)二分查找與bisect模塊詳解
二分查找又叫折半查找,二分查找應(yīng)該屬于減治技術(shù)的成功應(yīng)用。python標(biāo)準(zhǔn)庫(kù)中還有一個(gè)灰常給力的模塊,那就是bisect。這個(gè)庫(kù)接受有序的序列,內(nèi)部實(shí)現(xiàn)就是二分。下面這篇文章就詳細(xì)介紹了Python如何實(shí)現(xiàn)二分查找與bisect模塊,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-01-01
Python 讀取某個(gè)目錄下所有的文件實(shí)例
今天小編就為大家分享一篇Python 讀取某個(gè)目錄下所有的文件實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-06-06
django echarts餅圖數(shù)據(jù)動(dòng)態(tài)加載的實(shí)例
今天小編就為大家分享一篇django echarts餅圖數(shù)據(jù)動(dòng)態(tài)加載的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-08-08
使用Python實(shí)現(xiàn)將Word文檔轉(zhuǎn)換為PNG圖片
在這篇博客中,我將介紹一個(gè)使用Python編寫(xiě)的小工具,它能夠?qū)⒅付ㄎ募A中的所有Word文檔轉(zhuǎn)換為PNG圖片,這個(gè)工具基于wxPython庫(kù)構(gòu)建圖形用戶界面,接下來(lái),我將詳細(xì)說(shuō)明這個(gè)工具的功能及其實(shí)現(xiàn),需要的朋友可以參考下2024-08-08
Python從wsgi導(dǎo)入失敗的問(wèn)題解決方法
本文主要介紹了Python從wsgi導(dǎo)入失敗的問(wèn)題解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2025-04-04
python神經(jīng)網(wǎng)絡(luò)Inception?ResnetV2模型復(fù)現(xiàn)詳解
這篇文章主要為大家介紹了python神經(jīng)網(wǎng)絡(luò)Inception?ResnetV2模型復(fù)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05

