在機器學習常用的python包anconda下,安裝pytorch的步驟非常簡答
安裝命令:
conda install pytorch torchvision -c pytorch -y
直接一步到位!
如果安裝過程中,出現下面的連接http時獲取URL內容方面的錯誤時,沒關係,再重新運行安裝命令,多試幾次,相信你總能成功的!
Downloading and Extracting Packages
pytorch-1.1.0 | 49.9 MB | ################7 | 14%
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/pytorch/osx-64/pytorch-1.1.0-py3.7_0.tar.bz2>
Elapsed: -
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
驗證安裝是否成功:
import torch
print(torch.rand(2, 3))
執行後輸出類似於:
tensor([[0.6122, 0.4238, 0.0422],
[0.8809, 0.5974, 0.5142]])
恭喜你安裝成功!