pytorch的简介
PyTorch既可以看作加入了GPU支持的numpy,同时也可以看成一个拥有自动求导功能的强大的深度神经网络。pytorch百度百科
它是一个基于Python的可续计算包,提供两个高级功能:1、具有强大的GPU加速的张量计算(如NumPy)。2、包含自动求导系统的的深度神经网络。
出现的问题以及解决过程记录
-直接使用pip安装:pip install torch
出现的问题是:Running setup.py install for torch ... error
-使用官网下载的whl包
网址:https://download.pytorch.org/whl/torch_stable.html
在这里要注意版本信息:
cu92: cuda9.2
torch-1.4.0 : torch版本 1.4.0
cp37 : python版本3.7
win: windows 系统
我下载的是:
https://www.vocabulary.com/lists/6978474
cu102/torchvision-0.7.0-cp38-cp38-win_amd64.whl
cu102/torch-1.6.0-cp38-cp38-win_amd64.whl
https://www.vocabulary.com/lists/6978666
在使用pip安装时再次报错:torch-1.6.0-cp38-cp38-win_amd64.whl is not a supported wheel on this platform.
此次报错是pip不支持改文件名称,百度之后发现可以通过查看pip支持的文件名格式,改名解决问题。
import pip
print(pip.pep425tags.get_supported())
- 1
- 2
运行完之后报错:AttributeError: module 'pip' has no attribute 'pep425tags'
再次查找资料,提示64位应该使用:
import pip._internal
print(pip._internal.pep.get_supported())
- 1
- 2
运行之后仍然报错:AttributeError: module 'pip._internal' has no attribute 'pep425tags'
最后使用了另一个命令查看:
import wheel.pep425tags as w
print(w.get_supported())
#如果第二句报错,使用:
#print(w.get_supported("win_amd64"))
得到结果:
[('cp37', 'cp37m', 'win_amd64'), ('cp37', 'none', 'win_amd64'), ('cp37', 'none', 'any'), ('cp3', 'none', 'any'), ('cp36', 'none', 'any'), ('cp35', 'none', 'any'), ('cp34', 'none', 'any'), ('cp33', 'none', 'any'), ('cp32', 'none', 'any'), ('cp31', 'none', 'any'), ('cp30', 'none', 'any'), ('py3', 'none', 'win_amd64'), ('py37', 'none', 'any'), ('py3', 'none', 'any'), ('py36', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]
- 1
使用这种方法改完名字之后,还是error
,无奈,只能换!!!!!
- 使用Anaconda Prompt的conda命令安装
百度是个好地方,找到方法→win10从零安装配置pytorch全过程图文详解文章已经介绍的很不错了,步骤也很全。但是我又双叒叕出错了,记录一下:
打开anaconda prompt之后,运行命令都是Solving environment: failed
,使用更新命令conda update -n base conda
也是报错Solving environment: failed
,后来还是度娘指导了我:https://www.vocabulary.com/lists/6978759通过在anaconda cmd中输入“conda config --show-sources"
找到.condac文件,将以下内容粘贴:
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
后来实践证明,这一步要在win10从零安装配置pytorch全过程图文详解之前做完,因为教程内部的命令会更改.condac文件的配置内容。方法参照:anaconda 报错之Solving environment: failed,完成这一步之后,就可以conda create -n your_env_name python = x.x
,然后使用环境安装包了。
部分代码展示
(base) C:\Users\DELL>conda create -n pytorch python=3.8
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.5.11
latest version: 4.8.4
Please update conda by running
$ conda update -n base -c defaults conda
## Package Plan ##
environment location: E:\SOFT\Anaconda\envs\pytorch
added / updated specs:
- python=3.8
The following packages will be downloaded:
package | build
---------------------------|-----------------
wincertstore-0.2 | py38_0 15 KB defaults
zlib-1.2.11 | h62dcd97_4 132 KB defaults
wheel-0.35.1 | py_0 36 KB defaults
python-3.8.5 | h5fd99cc_1 18.7 MB defaults
certifi-2020.6.20 | py38_0 160 KB defaults
sqlite-3.33.0 | h2a8f88b_0 1.3 MB defaults
vs2015_runtime-14.16.27012 | hf0eaf9b_3 2.4 MB defaults
openssl-1.1.1g | he774522_1 5.8 MB defaults
pip-20.2.2 | py38_0 2.0 MB defaults
ca-certificates-2020.7.22 | 0 164 KB defaults
setuptools-49.6.0 | py38_0 958 KB defaults
------------------------------------------------------------
Total: 31.6 MB
The following NEW packages will be INSTALLED:
ca-certificates: 2020.7.22-0 defaults
certifi: 2020.6.20-py38_0 defaults
openssl: 1.1.1g-he774522_1 defaults
pip: 20.2.2-py38_0 defaults
python: 3.8.5-h5fd99cc_1 defaults
setuptools: 49.6.0-py38_0 defaults
sqlite: 3.33.0-h2a8f88b_0 defaults
vc: 14.1-h0510ff6_4 defaults
vs2015_runtime: 14.16.27012-hf0eaf9b_3 defaults
wheel: 0.35.1-py_0 defaults
wincertstore: 0.2-py38_0 defaults
zlib: 1.2.11-h62dcd97_4 defaults
Proceed ([y]/n)? y
选择yes
Downloading and Extracting Packages
wincertstore-0.2 | 15 KB | ############################################################################ | 100%
zlib-1.2.11 | 132 KB | ############################################################################ | 100%
wheel-0.35.1 | 36 KB | ############################################################################ | 100%
python-3.8.5 | 18.7 MB | ############################################################################ | 100%
certifi-2020.6.20 | 160 KB | ############################################################################ | 100%
sqlite-3.33.0 | 1.3 MB | ############################################################################ | 100%
vs2015_runtime-14.16 | 2.4 MB | ############################################################################ | 100%
openssl-1.1.1g | 5.8 MB | ############################################################################ | 100%
pip-20.2.2 | 2.0 MB | ############################################################################ | 100%
ca-certificates-2020 | 164 KB | ############################################################################ | 100%
setuptools-49.6.0 | 958 KB | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate pytorch
#
# To deactivate an active environment, use
#
# $ conda deactivate
(base) C:\Users\DELL>conda activate pytorch
(pytorch) C:\Users\DELL>
做到这一步是代表conda create -n your_env_name python = x.x
成功,接下来按照win10从零安装配置pytorch全过程图文详解继续做,根绝自己的电脑配置来。
Downloading and Extracting Packages
vs2015_runtime-14.16 | 2.4 MB | ############################################################################ | 100%
libssh2-1.9.0 | 218 KB | ############################################################################ | 100%
mkl-service-2.3.0 | 200 KB | ############################################################################ | 100%
conda-package-handli | 678 KB | ############################################################################ | 100%
pytorch-1.6.0 | 175.8 MB | ############################################################################ | 100%
mkl_random-1.1.0 | 270 KB | ################################################################################################################################################# | 100%
sqlite-3.33.0 | 1.3 MB | ################################################################################################################################################# | 100%
conda-4.8.4 | 3.1 MB | ################################################################################################################################################# | 100%
certifi-2020.6.20 | 160 KB | ################################################################################################################################################# | 100%
numpy-base-1.19.1 | 4.9 MB | ################################################################################################################################################# | 100%
mkl_fft-1.1.0 | 132 KB | ################################################################################################################################################# | 100%
pycurl-7.43.0.5 | 69 KB | ################################################################################################################################################# | 100%
libcurl-7.71.1 | 289 KB | ################################################################################################################################################# | 100%
curl-7.43.0 | 292 KB | ################################################################################################################################################# | 100%
numpy-1.19.1 | 21 KB | ################################################################################################################################################# | 100%
qt-5.9.7 | 92.3 MB | ################################################################################################################################################# | 100%
cryptography-3.1 | 592 KB | ################################################################################################################################################# | 100%
krb5-1.18.2 | 848 KB | ################################################################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
- 1
安装完成Torch之后,需要在pycharm中配置(pycharm与anaconda共享库),https://www.vocabulary.com/lists/6978925配置完成之后,导包import torch
不出错则成功。方法参考大概步骤如下:
最后可检查导入
import torch
- 1
… …
希望对翻到的你有所帮助,也欢迎补充学习