1. 程式人生 > >ubuntu 16.04下安裝torch和torchvision

ubuntu 16.04下安裝torch和torchvision

[email protected]:~$ 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.

這裡報錯啦,我們按照提示解決問題就好了

第三步:解決問題

[email protected]:~$ pip install /home/frank/torch-0.4.1-cp35-cp35m-linux_x86_64.whl^C
[email protected]:~$ 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
[email protected]
:~$

第四步:測試

[email protected]:~$ 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 "<stdin>", line 1, in <module>
  File "/home/frank/.local/lib/python3.5/site-packages/torch/__init__.py", line 80, in <module>
    from torch._C import *
ImportError: numpy.core.multiarray failed to import
>>> exit()

報錯了,這是因為torchvision還沒有安裝上,我們安裝上再試一試。 第五步:安裝torchvision

[email protected]:~$ 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

安裝成功啦!!! 第六步:再測試

[email protected]:~$ 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
>>> 

搞定!可以去跑程式碼啦。