linux ubuntu 16.04 python3.5 cuda9使用pip安装pytorch

按照官网的指导安装也会出错? 

 

报错:Could not find a version that satisfies the requirement torch==1.2.0+cu92

$ sudo -H pip --proxy=xx.xxx.xx.xxx:8080 install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html


# 报错:
Collecting torch==1.2.0+cu92
  Could not find a version that satisfies the requirement torch==1.2.0+cu92 (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2, 0.1.6.post17, 0.1.6.post20, 0.3.0.post4, 0.3.1, 0.4.0, 0.4.1, 1.0.0, 1.0.1, 1.0.1.post2, 1.1.0)
No matching distribution found for torch==1.2.0+cu92
You are using pip version 8.0.2, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

原因:pip版本不对!太老了!我把pip8升级到pip19解决了这个问题。

解决:

# 1,升级pip
$ sudo -H pip3 --proxy=xx.xxx.xx.xxx:8080 install --upgrade pip

# 输出:
Cache entry deserialization failed, entry ignored
Collecting pip
  Downloading https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl (1.4MB)
    100% |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒| 1.4MB 95kB/s
Installing collected packages: pip
  Found existing installation: pip 8.0.2
    Uninstalling pip-8.0.2:
      Successfully uninstalled pip-8.0.2
Successfully installed pip-19.2.3

# 2,重新按照官网的指导,安装pytorch
# 参考:https://pytorch.org/get-started/locally/
$ sudo -H pip3 --proxy=xx.xxx.xx.xxx:8080 install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html

# 3,安装成功看一下:
$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import torchvision
>>> torch.__version__
'1.2.0+cu92'
>>> torchvision.__version__
'0.4.0+cu92'

 

# 其他报错:error: package directory 'torch/cuda' does not exist

# 直接安装会出错
$ sudo -H pip --proxy=xx.xxx.xx.xxx:8080 install torch torchvision cu90

# 报错
Collecting torch
  Using cached https://files.pythonhosted.org/packages/f8/02/880b468bd382dc79896eaecbeb8ce95e9c4b99a24902874a2cef0b562cea/torch-0.1.2.post2.tar.gz
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info/torch.egg-info
    writing top-level names to pip-egg-info/torch.egg-info/top_level.txt
    writing pip-egg-info/torch.egg-info/PKG-INFO
    writing requirements to pip-egg-info/torch.egg-info/requires.txt
    writing dependency_links to pip-egg-info/torch.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/torch.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found

    error: package directory 'torch/cuda' does not exist

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-bsq0oe_b/torch
You are using pip version 8.0.2, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

原因:pytorch不是原生自带cuda,需要按照官网的指导进行安装,选择带有cuda的pytorch版本

解决:升级pip,使用官网指导的安装命令进行安装。如 

pip3 install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html

(不同环境对应的安装命令可能不一样,标题对应的环境使用上面这个命令就可以,xx.xxx.xx.xxx是因为内网需要代理才能上网。外网可以直接用上面这个命令)

你可能感兴趣的:(Python,#,CV-基础,#,DL-基础)