為了防止自己遺忘安裝過(guò)程,同時(shí)能對(duì)需要的人提供幫助,故寫該教程。
一、安裝Anaconda
1.下載安裝包
這里進(jìn)入官網(wǎng),進(jìn)行下載Anaconda | Anaconda DistributionAnaconda's open-source Distribution is the easiest way to perform Python/R data science and machine learning on a single machine.https://www.anaconda.com/products/distribution#download-section
?找到對(duì)應(yīng)的python版本,進(jìn)行下載。
完成下載后,輸入指令:
cd <下載路徑>
bash <該路徑下.sh為后綴的Anaconda安裝包>
根據(jù)提示信息進(jìn)行安裝(全部enter)
2.配置環(huán)境變量
which anaconda #找到安裝好的conda路徑
vim ~/.bashrc
export PATH="/conda的路徑:$PATH" #例如export PATH="/home/fyq/anaconda3/bin:$PATH"
source ~/.bashrc
3.驗(yàn)證安裝
輸入指令:
conda --version
得到輸出,完成Anaconda的安裝
二、配置虛擬環(huán)境
?由于它的源是在國(guó)外,故下載時(shí)常會(huì)出現(xiàn)速度慢,且不穩(wěn)定,還時(shí)常報(bào)錯(cuò),故這里使用清華的鏡像源。清華大學(xué)開(kāi)源軟件鏡像站 | Tsinghua Open Source Mirror
輸入指令添加鏡像源
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/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
輸入指令,驗(yàn)證其已成功添加:
conda config --show channels
可見(jiàn)輸出以下內(nèi)容
?創(chuàng)建虛擬環(huán)境:
conda create -n <環(huán)境名稱自定義> python=<python的版本號(hào)>
#例如conda create -n pytorch python=3.8
(這里創(chuàng)建了一個(gè)名為pytorch的虛擬環(huán)境)
輸出如下時(shí),創(chuàng)建成功
?如果在該過(guò)程中報(bào)錯(cuò),可嘗試輸入如下指令,更新conda后,再次創(chuàng)建
conda update --all
創(chuàng)建好虛擬環(huán)境后,輸入指令,進(jìn)入該虛擬環(huán)境:
source activate <你創(chuàng)建的虛擬環(huán)境名稱>
#例如source activate pytorch
輸出如下,括號(hào)中的即為你虛擬環(huán)境的名稱
?三、安裝pytorch
由于虛擬機(jī)的限制,為這里安裝的pytorch為cpu版本的。(以下內(nèi)容都在上述創(chuàng)建的虛擬環(huán)境中進(jìn)行)
進(jìn)入pytorch的官網(wǎng),找到你要安裝的版本
得到安裝指令:
conda install pytorch torchvision torchaudio cpuonly -c pytorch
后刪除其中的 -c pytorch ,其作用是從默認(rèn)的倉(cāng)庫(kù)里進(jìn)行安裝pytorch,而我們這里使用的是清華源故需要將其刪除,如果你要從默認(rèn)源安裝的話,直接輸入該指令即可。
輸入指令,安裝pytorch
conda install pytorch torchvision torchaudio cpuonly
輸出如下內(nèi)容時(shí)完成安裝
?驗(yàn)證安裝:
python3
import torch
torch.__version__ #各有兩條下劃線 _ _
輸出如下,即安裝成功
?四、安裝spikingjelly
輸入指令:
pip install spikingjelly
輸出如下:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-448835.html
?即安裝成功。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-448835.html
到了這里,關(guān)于Ubuntu20.04安裝pytorch(包括安裝Anaconda和虛擬環(huán)境配置以及安裝包spikingjelly)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!