pytorchGPU版本下载,解决torch.cuda.is_available()返回False的问题(CUDA11.6,python3.9)

当CUDA版本为11.6且torch.cuda.is_available()返回False时,文章提供了详细步骤来解决这一问题。首先,确认环境中无冲突的PyTorch版本,然后卸载所有PyTorch,再通过指定CUDA版本的whl文件进行重新安装,以确保与CUDA版本匹配。最后,验证安装是否成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(没下载过pytorch直接从第四步开始)
首先查看CUDA版本
cmd中输入 NVIDIA-smi
pip -V
我的版本是CUDA11.6,python3.9
在这里插入图片描述
import torch没有问题但是torch.cuda.is_available()此时返回的false,故进行以下操作:
1.在base环境中输入 pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
此时报错:
在这里插入图片描述
原因是可能在当前环境中之前安装过 PyTorch,并import torch选择了 CUDA运行时附带的“默认”安装。
需要卸载所有 PyTorch直到找不到任何安装。

2.输入conda list 发现此时列表中有pytorch在这里插入图片描述
3.在base环境中使用pip卸载Pytorch
pip uninstall torch torchvision -y
4.再重新运行
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
不过这个文件有2GB多,下载速度太慢,如果网速不好很可能下载失败。
在这里插入图片描述

5.在浏览器中输入网址
https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp39-cp39-win_amd64.whl
https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp39-cp39-win_amd64.whl

直接把文件下载下来,
在这里插入图片描述
6.再在base环境中输入pip install 并将文件直接拖进来
同理对另一个文件也进行如上操作
举个栗子,我存放的位置是D:\torchvision-0.14.1+cu117-cp39-cp39-win_amd64.whl
就输入 pip install D:\torchvision-0.14.1+cu117-cp39-cp39-win_amd64.whl
7.最后检验安装是否成功
在这里插入图片描述

这个问题怎么解决 Successfully uninstalled torchaudio-2.0.2 Successfully installed fsspec-2024.6.1 nvidia-cublas-cu11-11.11.3.6 nvidia-cuda-cupti-cu11-11.8.87 nvidia-cuda-nvrtc-cu11-11.8.89 nvidia-cuda-runtime-cu11-11.8.89 nvidia-cudnn-cu11-8.7.0.84 nvidia-cufft-cu11-10.9.0.58 nvidia-curand-cu11-10.3.0.86 nvidia-cusolver-cu11-11.4.1.48 nvidia-cusparse-cu11-11.7.5.86 nvidia-nccl-cu11-2.19.3 nvidia-nvtx-cu11-11.8.86 torch-2.2.1+cu118 torchaudio-2.2.1+cu118 torchvision-0.17.1+cu118 triton-2.2.0 (666) tom@objective-stellar-1724-575f654f49-wf6g5:~/fssd$ python Python 3.9.23 | packaged by conda-forge | (main, Jun 4 2025, 17:57:12) [GCC 13.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import torch A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.2 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with &#39;pybind11>=2.12&#39;. If you are a user of the module, the easiest solution will be to downgrade to &#39;numpy<2&#39; or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2. Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/conda/envs/666/lib/python3.9/site-packages/torch/__init__.py", line 1477, in <module> from .functional import * # noqa: F403 File "/opt/conda/envs/666/lib/python3.9/site-packages/torch/functional.py", line 9, in <module> import torch.nn.functional as F File "/opt/conda/envs/666/lib/python3.9/site-packages/torch/nn/__init__.py", line 1, in <module> from .modules import * # noqa: F403 File "/opt/conda/envs/666/lib/python3.9/site-packages/torch/nn/modules/__init__.py", line 35, in <module> from .transformer import TransformerEncoder, TransformerDecoder, \ File "/opt/conda/envs/666/lib/python3.9/site-packages/torch/nn/modules/transformer.py", line 20, in <module> device: torch.device = torch.device(torch._C._get_default_device()), # torch.device(&#39;cpu&#39;), /opt/conda/envs/666/lib/python3.9/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:84.) device: torch.device = torch.device(torch._C._get_default_device()), # torch.device(&#39;cpu&#39;),
最新发布
07-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值