ubuntu安裝pytorch以及遇到的問題

沒有科學上網工具就別嘗試pytorch官網給出的安裝方案了,網速跟不上.沒這金剛鑽攬啥瓷器活!!!
通過國內鏡像安裝方式如下:
先看自己CUDA對應的torch版本,然後:

pip install --default-timeout=100 -i https://mirrors.aliyun.com/pypi/simple torch==1.2.0

–default-timeout=100 表示延遲,如果網速跟不上,加入這個參數.
torch==1.2.0是我要下載的版本

問題1: 如果下載完torch後,附帶的numpy等包沒下完就突然斷開連接,那麼再繼續使用上一條命令下載可能會報錯.

        Expected sha256 a13bf6f78a49d844b85c142b8cd62d2e1833a11ed21ea0bc6b1ac73d24c76415
             Got        58c19649b1b84c9bb1847e92a70d500ce616486f1c39cd399eb3de7d157fdd8a

此時,解決辦法是下載另外一個版本的torch,下載完成後再卸載,然後再重新下載1.2.0版本。
改進上一條命令,多加一個 –upgrade ,也就是下載最新版本的torch。並且刪除指定版本(刪除==1.2.0),直接用torch代替.
注意:這時下載,版本會更改爲最新版本.

pip install --default-timeout=100 --upgrade -i https://mirrors.aliyun.com/pypi/simple torch

問題2: 假如這時才下載一半, 突然網速很慢,出現斷連問題,可能需要替換之前的鏡像源:

清華源: https://pypi.tuna.tsinghua.edu.cn/simple
中科大源: https://pypi.mirrors.ustc.edu.cn/simple
阿里雲源: https://mirrors.aliyun.com/pypi/simple

總有一個適合你, 親測阿里雲最快,且下載成功。
如前面所說,需要卸載最新版本,再重裝指定版本,鏡像源也要改爲上一步能成功下載的鏡像:

pip uninstall torch
pip install --default-timeout=100 -i https://mirrors.aliyun.com/pypi/simple torch==1.2.0

安裝完成後測試是否安裝成功,在終端輸入python,再輸入import torch,如果沒報錯,那麼安裝成功。

(pytorch) jim@jim-Vostro-3670:~$ python
Python 3.5.5 | packaged by conda-forge | (default, Jul 23 2018, 23:45:43) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> 

另外,還需要安裝torchvision,注意torchvision與torch的版本對應關係:

pip install -i https://mirrors.aliyun.com/pypi/simple torchvision==0.4.0

同理,測試是否安裝成功:

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