ubuntu 16.04下安装torch和torchvision

不喜欢ubuntu ,刚刚接触没两个月,但是我在学习pytorch时,跑一个程序,数据集下载下来是tar.gz的格式,程序中输出图片的功能显示不出来,只好跑到ubuntu下试试,那就安装pytorch吧首先。(这里补充一下,程序是pytorch官网提供的cifar10案例,程序需要加上plt.show(),就可以显示图像了,后来解决的)
第一步:去官网找对应版本下载。
链接:(https://pytorch.org/get-started/locally/)
可参考博客:(https://blog.csdn.net/weixin_43012220/article/details/83786637)
但是由于网速的限制,在终端下载特别慢,所以个人建议,先把torch的包下载下来,即(http://download.pytorch.org/whl/cpu/torch-0.4.1-cp35-cp35m-linux_x86_64.whl)这个是我的电脑安装的版本。
第二步:安装torch

frank@frank-Lenovo:~$ pip install /home/frank/torch-0.4.1-cp35-cp35m-linux_x86_64.whl
Processing ./torch-0.4.1-cp35-cp35m-linux_x86_64.whl
Installing collected packages: torch
Could not install packages due to an EnvironmentError: [Errno 13] 权限不够: '/usr/local/lib/python3.5/dist-packages/torch'
Consider using the `--user` option or check the permissions.

这里报错啦,我们按照提示解决问题就好了

第三步:解决问题

frank@frank-Lenovo:~$ pip install /home/frank/torch-0.4.1-cp35-cp35m-linux_x86_64.whl^C
frank@frank-Lenovo:~$ pip install --user /home/frank/torch-0.4.1-cp35-cp35m-linux_x86_64.whl
Processing ./torch-0.4.1-cp35-cp35m-linux_x86_64.whl
Installing collected packages: torch
Successfully installed torch-0.4.1
frank@frank-Lenovo:~$ 

第四步:测试

frank@frank-Lenovo:~$ python
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/frank/.local/lib/python3.5/site-packages/torch/__init__.py", line 80, in 
    from torch._C import *
ImportError: numpy.core.multiarray failed to import
>>> exit()

报错了,这是因为torchvision还没有安装上,我们安装上再试一试。
第五步:安装torchvision

frank@frank-Lenovo:~$ pip install --user torchvision
Collecting torchvision
  Using cached https://files.pythonhosted.org/packages/ca/0d/f00b2885711e08bd71242ebe7b96561e6f6d01fdb4b9dcf4d37e2e13c5e1/torchvision-0.2.1-py2.py3-none-any.whl
Collecting numpy (from torchvision)
  Using cached https://files.pythonhosted.org/packages/86/04/bd774106ae0ae1ada68c67efe89f1a16b2aa373cc2db15d974002a9f136d/numpy-1.15.4-cp35-cp35m-manylinux1_x86_64.whl
Collecting pillow>=4.1.1 (from torchvision)
  Using cached https://files.pythonhosted.org/packages/bc/cc/b6e47b0075ca4267855d77850af7ea4194d2fc591664f1d70e5151b50637/Pillow-5.3.0-cp35-cp35m-manylinux1_x86_64.whl
Requirement already satisfied: torch in ./.local/lib/python3.5/site-packages (from torchvision) (0.4.1)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from torchvision) (1.10.0)
Installing collected packages: numpy, pillow, torchvision
Successfully installed numpy-1.15.4 pillow-5.3.0 torchvision-0.2.1

安装成功啦!!!
第六步:再测试

frank@frank-Lenovo:~$ python
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> 

搞定!可以去跑代码啦。

你可能感兴趣的:(小书python成长记录)