Pytorch Conda環(huán)境下載慢換源/刪源/恢復(fù)默認源的簡單操作
背景
隨著實驗增多,需要分割創(chuàng)建環(huán)境的情況時有出現(xiàn),在此情況下使用conda create --name xx python=3.10 pytorch torchvision pytorch-cuda -c nvidia -c pytorch -y這樣的指令創(chuàng)建時如果不換源,往往下載速度很慢,甚至于報錯CondaHTTPError: HTTP 000 CONNECTION FAILED for url之類的情況
這種創(chuàng)建環(huán)境太慢可能是鏡像源地址的問題,可以切換到國內(nèi)的鏡像源地址試試,具體就是修改一下conda的配置文件。
在linux和window環(huán)境下通用,當(dāng)然也強推vscode的wsl去直接對linux中文件簡單操作完成修改
臨時換源
比如pip某個包而不是新建一個環(huán)境時候,完全可以臨時換源,例如
pip install tqdm -i https://pypi.tuna.tsinghua.edu.cn/simple
乃至于某個環(huán)境,比如完備的github開源項目,存在setup.py和run.py,只需要對著已經(jīng)設(shè)置好的requirements.txt修改的時候,也一樣可以
pip install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple
永久換源
打開conda配置condarc
window情況
C:\Users.condarc(沒有就創(chuàng)建一個)
右鍵選擇在記事本中編輯
linux情況
gedit ~/.condarc 或者用wsl直接找到home→用戶名→文件夾下就是用戶環(huán)境默認配置
同樣右鍵選擇在記事本中/vim打開編輯
換源
在打開的文檔中粘貼以下內(nèi)容
如果想阿里云(版本不容易沖突,但不知道為什么下載慢
channels: - defaults show_channel_urls: true default_channels: - http://mirrors.aliyun.com/anaconda/pkgs/main - http://mirrors.aliyun.com/anaconda/pkgs/r - http://mirrors.aliyun.com/anaconda/pkgs/msys2 - custom_channels: conda-forge: http://mirrors.aliyun.com/anaconda/cloud msys2: http://mirrors.aliyun.com/anaconda/cloud bioconda: http://mirrors.aliyun.com/anaconda/cloud menpo: http://mirrors.aliyun.com/anaconda/cloud pytorch: http://mirrors.aliyun.com/anaconda/cloud simpleitk: http://mirrors.aliyun.com/anaconda/cloud
如果想騰訊云(下載速度快!有些包比阿里云上要快個四五倍,但可能在GPU機器上下載到CPU版本的torch很難繃
channels: - defaults show_channel_urls: true channel_alias: http://mirrors.tuna.tsinghua.edu.cn/anaconda default_channels: - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ - custom_channels: conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
執(zhí)行配置
在Windows下修改完畢可以打開Anaconda Prompt,在命令行輸入執(zhí)行
conda config --set show_channel_urls yes
在linux中修改完畢可以ctrl+~(tab上邊那和)來打開終端執(zhí)行修改
source ~/.bashrc
命令行修改源
添加源
pip config set global.index-url --site https://pypi.tuna.tsinghua.edu.cn/simple
查看源
pip config list
刪源
有時候可能存在源沖突情況需要刪除掉配置過的某個源
刪除源
pip config unset global.index-url
改Python源
export PATH="/home/xx/anaconda3/bin:$PATH" source ~/anaconda3/bin/activate #修改終端的默認 python 為 anaconda
恢復(fù)默認源
如果搞了半天出問題,比如某些特殊的庫在清華源阿里源都沒有的話
返回到默認源慢慢下載或許反而能正常使用
conda config --remove-key channels
使用示范
針對類似于 conda create --name VLM python=3.10 pytorch torchvision pytorch-cuda -c nvidia -c pytorch -y 創(chuàng)建新環(huán)境情況
添加鏡像后,在conda下載安裝pytorch時(conda install pytorch torchvision cudatoolkit=10.2 -c pytorch)去掉 -c pytorch,執(zhí)行conda install pytorch torchvision cudatoolkit=10.2 ,否則還是會很慢。
添加鏡像后下載若還是出現(xiàn)錯誤,可以sudo gedit ~/.condarc 查看是否有一項default,將default一行刪除,保存.condarc文件并關(guān)閉,再次嘗試下載安裝。
以上就是Pytorch Conda環(huán)境下載慢換源/刪源/恢復(fù)默認源的簡單操作的詳細內(nèi)容,更多關(guān)于Pytorch Conda環(huán)境下載慢的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python實現(xiàn)http接口自動化測試的示例代碼
這篇文章主要介紹了Python實現(xiàn)http接口自動化測試的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10Windows系統(tǒng)下安裝tensorflow的配置步驟
這篇文章主要介紹了Windows系統(tǒng)下安裝tensorflow,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07