python - 无法在 Jupyter Notebook 或 Spyder for PyTorch 中获取可用的 cuda

标签 python jupyter-notebook pytorch

我已经使用 pip 和 conda 安装了 pytorch cuda

当我在空闲状态下运行此命令时:

>> import torch

>> torch.cuda.is_available()

我得到“真实”, 但在 Spyder 或 Jupyter Notebook 中,即使更新包和 conda 后,它也会显示为“False”。 pytorch cuda的conda更新从10.1到10.2

最佳答案

可以通过在conda中创建另一个环境然后安装torch来解决

类型:

>conda create -n yourenvname python=x.x anaconda

yourenvname 是环境名称

python=x.x 是适合您环境的 python 版本

使用以下方式激活环境:

>conda activate yourenvname

然后使用 cuda 安装 PyTorch:

>conda install pytorch torchvision cudatoolkit=10.2 -c pytorch

打开“spyder”或“jupyter笔记本” 验证是否已安装,输入:

> import torch
> torch.cuda.is_available()

关于python - 无法在 Jupyter Notebook 或 Spyder for PyTorch 中获取可用的 cuda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62423921/

相关文章:

Python - 试图捕获一行、正则表达式或拆分的中间

python - Jupyter 笔记本 : How to execute an external file containing imports and magic commands?

deep-learning - Pytorch : different behaviours in GAN training with different, 但概念上等效,代码

python - Numpy/PyTorch - 如何用不同维度的索引分配值?

python - 在 SQLAlchemy 中插入两个相关对象失败

python - 如何将C文件导入python

python - 在 Pandas 数据框中选择行时如何保持顺序?

python - 谷歌合作实验室: No module named pytextrank can be found (worked previously with the same notebook)

python - Jupyter、Python、%调试 : Setting breakpoint in module doesn't work

opencv - 如何得到YOLOv5模型的预测图像?