学习记录:Windows系统下cuda10.0选择安装python3.9版本后安装pytorch失败(附加解决方案)

前沿:

       个人比较偏向于用GPU训练,因此跑算法程序我都是用到cuda的,前几天我在cuda10.0基础上安装python3.9 版本,用标注工具labeling来标注图片。最近复现目标检测算法,我就在此基础上想要安装pytorch,安装失败,根据报错提示,原来是cuda10.0支持的torch版本太低了,无法匹配高版本python3.9。下面是pytorch安装失败的过程记录以及如何解决。

1、创建环境,激活环境

 

conda create -n mbjc python==3.9  #创建环境 python版本:3.9 环境名称:mbjc
conda activate mbjc               #激活环境 环境名称:mbjc

2、 查看python版本为3.9

(mbjc) C:\Users\24701>python
Python 3.9.0 (default, Nov 15 2020, 08:30:55) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'

去pytorch官网找到cuda10.0对应的torch版本:https://pytorch.org/get-started/previous-versions/

 复制命令行,安装pytorch

(mbjc) C:\Users\24701>conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch
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.
Solving environment: /
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
Examining python:  37%|██████████████████████▌                                      | 27/73 [00:00<00:00, 12463.81it/|
Examining wincertstore:  49%|████████████████████████████▌                             | 36/73 [04:05<03:44,  6.06s/i/
failed                                                                                                                 /
                                                                                                                       -
UnsatisfiableError: The following specifications were found                                                            |
to be incompatible with the existing python installation in your environment:

Specifications:

  - pytorch==1.2.0 -> python[version='>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0']
  - torchvision==0.4.0 -> python[version='>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0']

Your python: python==3.9

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

The following specifications were found to be incompatible with each other:



Package wincertstore conflicts for:
torchvision==0.4.0 -> python[version='>=3.5,<3.6.0a0'] -> pip -> setuptools -> wincertstore[version='>=0.2']
pytorch==1.2.0 -> python[version='>=3.7,<3.8.0a0'] -> pip -> setuptools -> wincertstore[version='>=0.2']
python==3.9 -> pip -> setuptools -> wincertstore[version='>=0.2']
Package setuptools conflicts for:
torchvision==0.4.0 -> python[version='>=3.5,<3.6.0a0'] -> pip -> setuptools
pytorch==1.2.0 -> python[version='>=3.7,<3.8.0a0'] -> pip -> setuptools
python==3.9 -> pip -> setuptools
Package msgpack-python conflicts for:
pytorch==1.2.0 -> python[version='>=3.7,<3.8.0a0'] -> pip -> cachecontrol -> msgpack-python[version='>=0.5.2']
torchvision==0.4.0 -> python[version='>=3.5,<3.6.0a0'] -> pip -> cachecontrol -> msgpack-python[version='>=0.5.2']
Package pip conflicts for:
torchvision==0.4.0 -> python[version='>=3.5,<3.6.0a0'] -> pip
pytorch==1.2.0 -> python[version='>=3.7,<3.8.0a0'] -> pip
python==3.9 -> pip

3、根据上述报错提示,发现cuda10.0对应的torch版本没问题,问题主要出现在python的版本, python 3.9 与 pytorch 1.2.0无法匹配造成的。需要我们重新创建一个兼容的环境即可。如何知道自己创建的python环境匹配cuda版本和torch版本呢??

下面展示了pytorch,torchvision,python 三者的对应关系,来源地址:https://github.com/pytorch/vision#installation

4、如果你是采用GPU进行训练的,那么需要安装cuda,cudnn以支持后续调用GPU进行运算。主流的深度学习框架都是基于cuda进行GPU并行加速的,而cudnn是针对深度卷积神经网络的加速库,两者都是一起安装的。

        这时在cuda的基础上安装pytorch时,需要注意cuda的版本型号,以本文为例cuda版本为10.0,因此去pytorch官网查询发现cuda10.0只支持pytorch<=1.2.0的版本,对应上表只能选择以下python版本。

 因此选择cuda10.0+pytorch1.2.0+python3.7是不可能出现版本不兼容的情况的。所以针对pytorch安装失败,在不改变cuda版本的情况下正确的做法就是重新创建一个python 3.7的环境。(python3.6也是可以的,python2.7和python3.5有可能会报错,自己没试过)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值