Ubuntu 16.04創建虛擬環境並安裝PyTorch GPU版

一、配置清華鏡像,這樣安裝包的時候會快不少

在anaconda安裝好之後,默認的鏡像是官方的,由於官網的鏡像在境外,使用國內的鏡像能夠加快訪問的速度。這裏選擇了清華的的鏡像。

在Anaconda Prompt中運行:

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 --set show_channel_urls yes

前往當前用戶的目錄下,查看.condarc文件:

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - defaults
show_channel_urls: true

 注意:配置完成之後,要關閉控制檯再重新打開控制檯,這樣新配置的文件纔會被加載進來

二、創建虛擬環境,注意創建虛擬環境時需要指定環境位置,否則可能不是創建在anaconda/envs下面(可能是配置了清華鏡像的緣故)

conda create --prefix=/home/anaconda/envs/yourEnvironmentName python=3.6

三、激活虛擬環境

conda activate yourEnvironmentName

四、安裝pytorch及CUDA和cudnn, 注意安裝包時需要指定虛擬環境,否則可能會安裝到別的虛擬環境中(可能是配置了清華鏡像的緣故)

conda install pytorch torchvision cudatoolkit=10.1 cudnn=7.6.4 -n yourEnvironmentName

五、驗證pytorch是否安裝成功

進入python命令行,輸入:

import torch
print(torch.cuda.is_available())

如果輸出爲True即代表安裝成功

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章