INT305 - Machine Learning - PyTorch 配置方法
-
安装
Anaconda3
运行安装程序
Anaconda3-2021.05-Windows-x86_64.exe
下载地址(清华镜像) https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ -
打开
Anaconda Powershell Prompt (anaconda3)
这里尝试了多种版本的组合,我是尝试到3.6.10
才成功,3.8
往上报错了,我也不知道为什么
需要注意的是,为了避免本地已经存在的环境,最好新建虚拟环境,再开始配置安装PyTorch
conda create -n PyTorch python==3.6.10
安装完成后,切换 base
到 PyTorch
环境路径下
conda activate PyTorch
安装操作,通过查询 PyTorch
官网 https://pytorch.org/ 获取用于 Conda
的安装命令
根据需求,选择 Stable - Windows - Conda - Python
由于项目简单不需要 GPU
加速,这里选择 CPU-Only
conda install pytorch torchvision torchaudio cpuonly -c pytorch
- 验证安装
安装完成后,在留在窗口内,打开 Python
python
import torch
x = torch.rand(2, 3)
print(x)
Anaconda Powershell Prompt (anaconda3)
不报错,并且有输出,则安装成功
tensor([[0.4516, 0.0617, 0.3831],
[0.6722, 0.4949, 0.7987]])
- 配置信息表
conda
信息
(PyTorch) PS C:\Users\name> conda info
active environment : PyTorch
active env location : D:\anaconda3\envs\PyTorch
shell level : 2
user config file : C:\Users\name\.condarc
populated config files : C:\Users\name\.condarc
conda version : 22.9.0
conda-build version : 3.21.4
python version : 3.8.8.final.0
virtual packages : __cuda=11.7=0
__win=0=0
__archspec=1=x86_64
base environment : D:\anaconda3 (writable)
conda av data dir : D:\anaconda3\etc\conda
conda av metadata url : None
channel URLs : https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
https://conda.anaconda.org/conda-forge/win-64
https://conda.anaconda.org/conda-forge/noarch
package cache : D:\anaconda3\pkgs
C:\Users\name\.conda\pkgs
C:\Users\name\AppData\Local\conda\conda\pkgs
envs directories : D:\anaconda3\envs
C:\Users\name\.conda\envs
C:\Users\name\AppData\Local\conda\conda\envs
platform : win-64
user-agent : conda/22.9.0 requests/2.25.1 CPython/3.8.8 Windows/10 Windows/10.0.19041
administrator : False
netrc file : None
offline mode : False
Python
信息
(PyTorch) PS C:\Users\name> python
Python 3.6.10 |Anaconda, Inc.| (default, May 7 2020, 19:46:08) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
~~Jason_liu O(∩_∩)O