Pytorch安装的一些问题
Pytorch(conda)安装
Pytorch安装(conda)的一些问题
问题:
最近安装了一下pytorch,前面安装了tensorflow没有遇到什么问题,就是直接在pycharm中搜索tensorflow-gpu版本并安装,gpu可用。但是照猫画虎的安装pytorch之后torch可用,但是Gpu不可用,torch.cuda.is_available()返回False。
尝试解决方法
1.更新Cuda,从此处下载cuda版本:下载地址参考文章:参考。一般情况参考中遇到的问题你都要解决,包括visual studio安装失败,nsight xxx安装失败等。安装目录最好不建议默认(刚开始没敢改结果少了几G)
仍存在问题:安装了10.1版本参考他人不同查看cuda方法看淡方法不同:
nvcc -V
结果:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:12:52_Pacific_Daylight_Time_2019
Cuda compilation tools, release 10.1, V10.1.243
nvidia-smi
结果:
NVIDIA-SMI 442.59 Driver Version: 442.59 CUDA Version: 10.2
最终并没有处理这个问题,(可能这两者反应的不是同一个问题,根本没有关联?)。
2. 更新Gpu 驱动,此处就不添加参考了。
3. 下载cudnn,下载地址:下载地址,将压缩包内相应的文件放入文件夹:https://developer.nvidia.com/cudnn下相应文件夹内覆盖。
最终上述的方法并没有解决gpu不可用的问题。
查看gpu是否支持:官网,最终发现本人1050ti没有在支持列表内,但是(tf可用?)这也在安装cuda的时候有体现,会warning,最终确认可以用。
常用方法:完成上述的gpu准备后,在官网选择自己自己相应的版本命令安装,(去掉“-c pytorch”命令参数,不然使用官网源速度慢)。但是我使用上述方法gpu仍不可用。
怀疑使用的torch是cpu版本(但是自己确实使用的非cpu版本安装命令),这个部分博客也说了这个问题,window下官网方法下载的是cpu版本,于时使用conda remove卸载原始的安装包,发现确实是cpu版本的。
卸载详情:
## Package Plan ##
environment location: E:\anaconda
removed specs:
- pytorch
The following packages will be downloaded:
package | build
---------------------------|-----------------
intel-openmp-2020.0 | 166 1.5 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
mkl-2020.0 | 166 98.9 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
------------------------------------------------------------
Total: 100.5 MB
The following packages will be REMOVED:
_pytorch_select-1.1.0-cpu
ninja-1.7.2-0
pytorch-1.0.1-cpu_py37h39a92a0_0
torchvision-0.2.1-py_2
在此过程中更改了conda channel,再使用官网方法安装报错。
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- torchvision
Current channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/main/win-64
- https://repo.anaconda.com/pkgs/main/noarch
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
解决方法:参考
使用命令查找可用的torch
anaconda search -t conda torch
结果返回了几百行,win下可用的不多,win下gpu可用的更少,最终选择:
pytorch/pytorch | 1.4.0 | conda | linux-64, osx-64, win-64 | py2.7_2, py27_cuda7.5.18_cudnn6.0.21hc114ab0_4, py2.7_0, py2.7_1, py3.5_cuda10.0.130_cudnn7.6.2_0, py35_cuda0.0_cudnn0.0_1, py3.7_cuda101_cudnn7_0, py35_cuda90_cudnn7he774522_1, py35_cuda0.0_cudnn0.0_2, py36_cuda9.0.176_cudnn7.0.3hdc18817_4, py3.7_cuda9.0.176_cudnn7.4.2_0, py3.7_cuda9.0.176_cudnn7.4.2_2, py37_cuda80_cudnn7he774522_1, py3.7_cuda9.2.148_cudnn7.6.2_0, py3.6_cuda9.0.176_cudnn7.5.1_0, py3.5_cuda9.0.176_cudnn7.4.2_2, py3.5_cuda10.0.130_cudnn7.4.1_1, py3.5_cuda9.0.176_cudnn7.4.2_0, py35_cuda9.0.176_cudnn7.0.3h5a7d906_4, py3.6_cuda9.0.176_cudnn7.4.2_2, py3.6_cuda9.0.176_cudnn7.4.2_0, py27_cuda8.0.61_cudnn7.0.3hb4df5cf_4, py3.5_cuda9.0.176_cudnn7.5.1_0, py3.6_cuda10.0.130_cudnn7.5.1_0, py2.7_cuda9.2.148_cudnn7.6.2_0, py3.6_0, py36_cuda9.1.85_cudnn7.0.5_nccl2_2, py3.8_cpu_0, py36_cuda9.1.85_cudnn7.1.2_1, py2.7_cuda8.0.61_cudnn7.1.2_0, py2.7_cuda10.1.243_cudnn7.6.3_0, py3.5_cuda100_cudnn7_1, py3.7_cuda10.0.130_cudnn7.6.2_0, py3.5_cuda8.0.61_cudnn7.1.2_2, py3.5_cuda8.0.61_cudnn7.1.2_1, py3.5_cuda8.0.61_cudnn7.1.2_0, py3.6_cuda9.0.176_cudnn7.4.1_1, py36_cuda9.1.85_cudnn7.0.5_2, py3.6_2, py3.8_cuda10.0.130_cudnn7.6.3_0, py36_cuda0.0_cudnn0.0h57b1bc9_4, py3.6_1, py3.6_cuda10.0.130_cudnn7.4.1_1, py27_cuda9.0.176_cudnn7.0.5_nccl2_2, py3.7_cuda10.0.130_cudnn7.4.2_2, py3.7_cuda10.0.130_cudnn7.4.2_0, py27_cuda0.0_cudnn0.0_2, py2.7_cuda10.0.130_cudnn7.6.2_0, py3.5_cuda10.0.130_cudnn7.5.1_0, py36_cuda9.0.176_cudnn7.0.5_nccl2_2, py3.7_cpu_0, py27_cuda9.0.176_cudnn7.1.2_1, py35_cuda8.0.61_cudnn7.0.3h4d8fc25_4, py3.7_cuda10.0.130_cudnn7.4.1_1, py3.5_cuda9.2.148_cudnn7.6.3_0, py36_cuda7.5.18_cudnn6.0.21h759af52_4, py3.6_cuda101_cudnn7_0, py35_cuda7.5.18_cudnn6.0.21h2ca90fe_4, py35_cuda9.0.176_cudnn7.0.5_nccl2_2, py2.7_cuda10.0.130_cudnn7.4.1_1, py35_cuda9.1.85_cudnn7.0.5_nccl2_2, py36_cuda9.0.176_cudnn7.1.2_1, py37_cuda9.2.148_cudnn7.1.4_1, py2.7_cuda10.0.130_cudnn7.5.1_0, py3.7_cuda8.0.61_cudnn7.1.2_2, py2.7_cuda9.0.176_cudnn7.4.1_1, py2.7_cuda10.0.130_cudnn7.4.2_2, py2.7_cuda10.0.130_cudnn7.4.2_0, py36_cuda8.0.61_cudnn7.0.5_2, py3.5_cuda9.0.176_cudnn7.4.1_1, py3.7_cpu_1, py3.7_cuda8.0.61_cudnn7.1.2_1, py3.7_cuda8.0.61_cudnn7.1.2_0, py3.7_cuda90_cudnn7_1, py2.7_cuda10.0.130_cudnn7.6.3_0, py27_cuda8.0.61_cudnn7.0.3hf383a3f_4, py3.5_cpu_1, py37_cuda90_cudnn7he774522_1, py3.5_cuda10.1.243_cudnn7.6.3_0, py35_cuda80_cudnn7he774522_1, py3.7_1, py3.7_0, py2.7_cpu_0, py3.6_cpu_1, py3.6_cpu_0, py27_cuda0.0_cudnn0.0he480db7_4, py27_cuda9.0.176_cudnn7.0.5_2, py3.6_cuda10.0.130_cudnn7.6.3_0, py3.6_cuda80_cudnn7_1, py27_cuda9.1.85_cudnn7.0.5_nccl2_2, py27_cuda9.0.176_cudnn7.0.3_nccl2h301e181_4, py3.7_cuda10.0.130_cudnn7.5.1_0, py3.6_cuda10.0.130_cudnn7.4.2_2, py3.6_cuda10.0.130_cudnn7.4.2_0, py27_cuda8.0.61_cudnn7.1.2_1, py3.6_cuda10.0.130_cudnn7.6.2_0, py36_cuda80_cudnn7he774522_1, py3.7_2, py35_py27__9.0.176_7.1.2_2, py3.6_cuda9.2.148_cudnn7.6.3_0, py36_cuda8.0.61_cudnn7.0.3h37a80b5_4, py35_cuda9.1.85_cudnn7.0.5_2, py3.7_cuda92_cudnn7_1, py3.7_cuda9.0.176_cudnn7.4.1_1, py3.7_cuda92_cudnn7_0, py27_cuda8.0.61_cudnn7.0.5_2, py27_cuda9.2.148_cudnn7.1.4_1, py3.6_cuda90_cudnn7_1, py27_cuda9.1.85_cudnn7.1.2_1, py2.7_cuda9.0.176_cudnn7.4.2_2, py2.7_cuda9.0.176_cudnn7.4.2_0, py3.5_cuda80_cudnn7_1, py3.8_cuda101_cudnn7_0, py3.5_cuda10.0.130_cudnn7.4.2_0, py35_cuda0.0_cudnn0.0hc53adbe_4, py3.7_cuda10.0.130_cudnn7.6.3_0, py3.5_cuda9.2.148_cudnn7.6.2_0, py3.5_1, py3.5_0, py3.5_2, py2.7_cuda8.0.61_cudnn7.1.2_2, py3.8_0, py36_cuda90_cudnn7he774522_1, py3.6_cuda10.1.243_cudnn7.6.3_0, py3.6_cuda92_cudnn7_0, py2.7_cuda9.0.176_cudnn7.5.1_0, py3.8_cuda9.2.148_cudnn7.6.3_0, py37_cuda0.0_cudnn0.0_1, py36_cuda9.0.176_cudnn7.0.5_2, py3.7_cuda9.2.148_cudnn7.6.3_0, py35_cuda9.2.148_cudnn7.1.4_1, py35_cuda9.0.176_cudnn7.0.3_nccl2h5f42aa5_4, py3.5_cpu_0, py36_cuda92_cudnn7he774522_1, py3.5_cuda101_cudnn7_0, py35_cuda8.0.61_cudnn7.0.3hb362f6e_4, py27__9.0.176_7.1.2_2, py36_cuda91_cudnn7he774522_1, py35_cuda8.0.61_cudnn7.0.5_2, py2.7_cuda8.0.61_cudnn7.1.2_1, py3.5_cuda10.0.130_cudnn7.4.2_2, py35_cuda91_cudnn7he774522_1, py3.6_cuda92_cudnn7_1, py36_py35_py27__9.0.176_7.1.2_2, py37_cuda92_cudnn7he774522_1, py3.7_cuda9.0.176_cudnn7.5.1_0, py27_cuda9.0.176_cudnn7.0.3hdbbd62b_4, py35_cuda9.0.176_cudnn7.0.5_2, py36_cuda9.0.176_cudnn7.0.3_nccl2h295ae03_4, py3.8_cuda92_cudnn7_0, py3.7_cuda80_cudnn7_1, py37_cuda8.0.61_cudnn7.1.2_1, py2.7_cuda9.2.148_cudnn7.6.3_0, py3.6_cuda9.2.148_cudnn7.6.2_0, py36_cuda9.2.148_cudnn7.1.4_1, py27_cuda0.0_cudnn0.0_1, py35_cuda9.1.85_cudnn7.1.2_1, py37_py36_py35_py27__9.0.176_7.1.2_2, py35_cuda92_cudnn7he774522_1, py3.6_cuda100_cudnn7_1, py3.5_cuda92_cudnn7_0, py3.5_cuda92_cudnn7_1, py3.7_cuda100_cudnn7_1, py35_cuda9.0.176_cudnn7.1.2_1, py3.6_cuda8.0.61_cudnn7.1.2_0, py3.6_cuda8.0.61_cudnn7.1.2_1, py3.6_cuda8.0.61_cudnn7.1.2_2, py3.7_cuda10.1.243_cudnn7.6.3_0, py36_cuda8.0.61_cudnn7.0.3hcf1d89b_4, py27_cuda9.1.85_cudnn7.0.5_2, py3.5_cuda10.0.130_cudnn7.6.3_0, py37_cuda9.0.176_cudnn7.1.2_1, py36_cuda8.0.61_cudnn7.1.2_3, py35_cuda8.0.61_cudnn7.1.2_1, py36_cuda8.0.61_cudnn7.1.2_1, py35_cuda8.0.61_cudnn7.1.2_3, py27_cuda8.0.61_cudnn7.1.2_3, py3.8_cuda10.1.243_cudnn7.6.3_0, py3.5_cuda90_cudnn7_1, py36_cuda0.0_cudnn0.0_1, py36_cuda0.0_cudnn0.0_2
: PyTorch is an optimized tensor library for deep learning using GPUs and CPUs.
使用命令下载(死马当活马医,也不知道能不能成功)
conda install -c https://conda.anaconda.org/pytorch pytorch
输出:
Collecting package metadata (current_repodata.json): done
Solving environment: -
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
- defaults/win-64::anaconda==custom=py37_1
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::astropy==4.0=py37he774522_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::bkcharts==0.2=py37_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::bokeh==2.0.0=py37_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::bottleneck==1.3.2=py37h2a96729_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch::dask==2.12.0=py_0
- defaults/win-64::gensim==3.8.0=py37hf9181ef_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::h5py==2.10.0=py37h5e291fa_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::imageio==2.6.1=py37_0
- conda-forge/noarch::keras-applications==1.0.8=py_1
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch::keras-preprocessing==1.1.0=py_1
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::matplotlib==3.1.3=py37_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::matplotlib-base==3.1.3=py37h64f37c6_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::mkl_fft==1.0.15=py37h14836fe_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::mkl_random==1.1.0=py37h675688f_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::numba==0.48.0=py37h47e9c7a_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::numexpr==2.7.1=py37h25d0782_0
- defaults/win-64::numpy==1.16.5=py37h19fb1c0_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch::opt_einsum==3.1.0=py_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::pandas==1.0.1=py37h47e9c7a_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::patsy==0.5.1=py37_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::pytables==3.5.2=py37h1da0976_1
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::pytest-arraydiff==0.3=py37h39e3cac_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch::pytest-astropy==0.8.0=py_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch::pytest-doctestplus==0.5.0=py_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::pywavelets==1.1.1=py37he774522_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::scikit-image==0.16.2=py37h47e9c7a_0
- defaults/win-64::scikit-learn==0.21.3=py37h6288b17_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::scipy==1.4.1=py37h9439919_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch::seaborn==0.10.0=py_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::statsmodels==0.11.0=py37he774522_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch::tensorboard==2.1.0=py3_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::tensorflow==2.1.0=gpu_py37h7db9008_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::tensorflow-base==2.1.0=gpu_py37h55f5790_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch::tensorflow-estimator==2.1.0=pyhd54b08b_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::tensorflow-gpu==2.1.0=h0d30ee6_0
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64::_anaconda_depends==2019.03=py37_0
done
## Package Plan ##
environment location: E:\anaconda
added / updated specs:
- pytorch
The following packages will be downloaded:
package | build
---------------------------|-----------------
numpy-1.16.5 | py37h19fb1c0_0 49 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pytorch-1.4.0 |py3.7_cuda101_cudnn7_0 472.8 MB pytorch
scikit-learn-0.22.1 | py37h6288b17_0 4.7 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
------------------------------------------------------------
Total: 477.5 MB
The following NEW packages will be INSTALLED:
ninja anaconda/pkgs/free/win-64::ninja-1.7.2-0
pytorch pytorch/win-64::pytorch-1.4.0-py3.7_cuda101_cudnn7_0
The following packages will be UPDATED:
scikit-learn pkgs/main::scikit-learn-0.21.3-py37h6~ --> anaconda/pkgs/main::scikit-learn-0.22.1-py37h6288b17_0
The following packages will be SUPERSEDED by a higher-priority channel:
numpy pkgs/main --> anaconda/pkgs/main
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
最终测试:
查看tf是否受影响:
问题
可能大多数开发者都在linux下吧,但是win下安装的也很少提到安装的只是cpu版本,因此一直以为是gpu环境问题,浪费了很长时间,也有很多安装的并没有测试gpu是否可用,也有再显卡设置里设置高性能显卡优先使用就解决了返回false的问题,但是确实我各种方法下自动给安装的都是cpu版本,所以最终的方法还是应该查找所有可用的pytorch版本,查看相应版本的环境,依据环境下载相应版本。