2019独角兽企业重金招聘Python工程师标准>>>
pytorch 官方网站。
官方网站提供多种安装方式,例如pip和conda等,可以参考官方安装文档,文档很详细,建议仔细查看和使用。但安装过程中可能存在网络不稳定导致无法正常安装等情况,需要使用离线方式下载whl文件安装。
pip安装软件可以使用国内安装源加速安装,可以参考安装教程。
首先不推荐pip安装方式。Windows 10 PowerShell安装很容易失败。具体日志如下:
#安装错误日志
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
PS C:\Windows\system32> pip install pytorch
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting pytorch
Downloading https://mirrors.aliyun.com/pypi/packages/a9/41/4487bc23e3ac4d674943176f5aa309427b011e00607eb98899e9d951f67b/pytorch-0.1.2.tar.gz
Building wheels for collected packages: pytorch
Building wheel for pytorch (setup.py) ... error
Complete output from command "c:\program files\python36\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\legion\\AppData\\Local\\Temp\\pip-install-yo1kyfd7\\pytorch\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\legion\AppData\Local\Temp\pip-wheel-ryvzo89f --python-tag cp36:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\legion\AppData\Local\Temp\pip-install-yo1kyfd7\pytorch\setup.py", line 17, in
raise Exception(message)
Exception: You should install pytorch from http://pytorch.org
----------------------------------------
Failed building wheel for pytorch
Running setup.py clean for pytorch
Failed to build pytorch
Installing collected packages: pytorch
Running setup.py install for pytorch ... error
Complete output from command "c:\program files\python36\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\legion\\AppData\\Local\\Temp\\pip-install-yo1kyfd7\\pytorch\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\legion\AppData\Local\Temp\pip-record-zmowtm8p\install-record.txt --single-version-externally-managed --compile:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\legion\AppData\Local\Temp\pip-install-yo1kyfd7\pytorch\setup.py", line 13, in
raise Exception(message)
Exception: You should install pytorch from http://pytorch.org
----------------------------------------
Command ""c:\program files\python36\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\legion\\AppData\\Local\\Temp\\pip-install-yo1kyfd7\\pytorch\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\legion\AppData\Local\Temp\pip-record-zmowtm8p\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\legion\AppData\Local\Temp\pip-install-yo1kyfd7\pytorch\
PS C:\Windows\system32>
正式开始安装 pytorch 前首先安装 torchvision 。
#torchvision 下载地址
https://pypi.org/project/torchvision/#files
#可能存在变动
pip install torchvision
#详细下载地址
pip install https://files.pythonhosted.org/packages/fb/01/03fd7e503c16b3dc262483e5555ad40974ab5da8b9879e164b56c1f4ef6f/torchvision-0.2.2.post3-py2.py3-none-any.whl
#conda 安装
conda install -c anaconda cudatoolkit
https://pytorch.org/get-started/previous-versions/ 可以下载不同版本pytorch。.whl文件可以使用浏览器或者迅雷下载。
本文以安装 python 3.7 CPU 版本为例。下载链接如下
https://download.pytorch.org/whl/cpu/torch-0.4.1-cp37-cp37m-win_amd64.whl
下载完毕,开始安装。
pip install torch-0.4.1-cp37-cp37m-win_amd64.whl
安装可能需要依赖numpy等,可以提前下载。地址如下
https://pypi.org/project/numpy/#files
本文推荐使用conda安装,可以解决部分情况下缺少部分C依赖库导致安装失败问题。
conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing
conda install pytorch