創(chuàng)建pytorch虛擬環(huán)境(GPU版本)
1.進(jìn)入anaconda的終端窗口
2.查看虛擬環(huán)境
conda env list
3.創(chuàng)建虛擬環(huán)境
注:可以先換源,否則后面下載很慢,換源可以參考其他博客,這里不在贅述
conda create -n pytorch (python=3.8,可寫可不寫)
4.創(chuàng)建完成之后,進(jìn)入虛擬環(huán)境
conda activate pytorch
5.進(jìn)入pytorch官網(wǎng),找到自己電腦可以接受的配置,復(fù)制安裝指令
官網(wǎng):https://pytorch.org/get-started/locally/
安裝指令:conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
刪除“-c pytorch” ,會(huì)使用你自己的源安裝,否則從pytorch官網(wǎng)上安裝。
6.復(fù)制安裝指令,粘貼到對(duì)話框,回車,安裝
在安裝pytorch的虛擬環(huán)境,復(fù)制安裝指令進(jìn)行安裝(手機(jī)開熱下載的會(huì)快很多或者換成鏡像源)
7.安裝完成后在Python中配置解釋器
File->Settings->Project:pytorch->Python Interpreter
8.輸入驗(yàn)證代碼,測(cè)試環(huán)境是否裝好
import?torch
flag?=?torch.cuda.is_available()
print(flag)
ngpu=?1
#?Decide?which?device?we?want?to?run?on
device?=?torch.device("cuda:0"?if?(torch.cuda.is_available()?and?ngpu?>?0)?else?"cpu")
print(device)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())
出現(xiàn)以下結(jié)果就是裝好了文章來源:http://www.zghlxwxcb.cn/news/detail-627271.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-627271.html
到了這里,關(guān)于安裝pytorch+配置pycharm解釋器(超級(jí)詳細(xì)適合小白)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!