anaconda安裝pytorch


1.先創建虛擬環境

conda create --name pytorch python=3.6
這里的pytorch是虛擬環境的名字

2.activate pytorch  進入虛擬環境

 

一般情況下,condarc文件出現在/home/user目錄下,但有時會出現找不到情況,解決辦法如下:

創建condarc文件命令
conda config --add channels r

即在/home/user目錄下出現condarc文件

換回默認源:conda config --remove-key channels

然后把這個文件換成清華鏡像的:

channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
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/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
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
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

若是直接用官網查找的的命令:

conda install pytorch torchvision cpuonly -c pytorch

進行安裝很容易發生CondaError: CondaHTTPError:這種錯誤

 

 

 

 

 

 

 在pytorch官網查找對應的命令:使用清華鏡像時需要去掉后面的  -c pytorch

conda install pytorch torchvision cpuonly

執行命令的同時會出現pytorch安裝的同時需要的包及其版本:

 

 

 

 

 

 然后又發生

PackageNotFoundError: Packages missing in current channels:

 

這個問題,於是我就在下面官網查找需要下載的torchvision的版本命令:conda install torchvision -c pytorch

https://pypi.org/project/torchvision/

最后:這個包下載成功

 

 

 然后繼續用清華鏡像的安裝命令:若顯示哪個包PackageNotFoundError,就去這個包的官網找對應版本單獨下載

或者使用

conda install pytorch torchvision cpuonly -c pytorch命令進行安裝



測試小代碼:
from __future__ import print_function
import torch
x = torch.empty(5, 3)
print(x)

   輸出:

tensor(1.00000e-04 *
       [[-0.0000,  0.0000,  1.5135],
        [ 0.0000,  0.0000,  0.0000],
        [ 0.0000,  0.0000,  0.0000],
        [ 0.0000,  0.0000,  0.0000],
        [ 0.0000,  0.0000,  0.0000]])




安裝過程中出現的問題:

CondaError: CondaHTTPError:

百度的解決辦法:

  編輯其中的 .condarc 文件

  刪除 - default

  將 - https://... 改成 - http://...

  我試了之后沒用

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM