Mac下使用Anaconda安装Pytorchfrom __future__ import print_function import torch x = torch.rand(5, 3) print

建立、激活、安装Pytorch

1. 打开终端,在上面输入:

conda create -n pytorch python=3.5

根据你的需要,可以选择不同版本的python。只需要将3.5改成3.6或者改成2.7即可

2. 然后等执行完毕之后,再执行:

source activate pytorch

至此就激活了运行环境。

3. 然后再执行

pip3 install torch torchvision

以进行Pytorch的安装。

验证PYTORCH安装

可将如下代码保存为test.py文件,执行python test.py进行验证

from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)

执行后输出类似于:

tensor([[0.3380, 0.3845, 0.3217],
        [0.8337, 0.9050, 0.2650],
        [0.2979, 0.7141, 0.9069],
        [0.1449, 0.1132, 0.1375],
        [0.4675, 0.3947, 0.1426]]

等结束后,至此安装完成。

猜你喜欢

转载自blog.csdn.net/qq_39362996/article/details/86566317