iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >关于安装 PyTorch-Lightning 的一些问题(GPU版)
  • 185
分享到

关于安装 PyTorch-Lightning 的一些问题(GPU版)

pythonpipcondapytorch深度学习 2023-09-06 16:09:05 185人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

官网地址: PyTorch PyTorch-Lightning 安装PyTorch-Lightning 不能直接使用pip install pytorch-lightning ,否则如下图会直接卸载掉你的torch而安装cpu版本

官网地址:

PyTorch

PyTorch-Lightning

安装PyTorch-Lightning

不能直接使用pip install pytorch-lightning ,否则如下图会直接卸载掉你的torch而安装cpu版本的torch。

Installing collected packages: torch, lightning_fabric  Attempting uninstall: torch    Found existing installation: torch 1.9.1+cu111    Uninstalling torch-1.9.1+cu111:      Successfully uninstalled torch-1.9.1+cu111

安装pytorch-lightning时一定注意自己的torch是pip安装还是conda安装,两者要保持一致,否则也会导致你的torch版本被替换。

正确安装方式:pip install pytorch-lightning==版本名

验证PyTorch和PyTorch-Lightning版本

 在python中导入PyTorch,然后打印出其版本号来查看,示例代码如下:

import torchprint(torch.__version__)

使用以下代码来查看已安装的 PyTorch-Lightning 版本: 

import pytorch_lightning as plprint(pl.__version__)

验证GPU是否能用

import torchif torch.cuda.is_available():    print("CUDA is available")else:    print("CUDA is not available")
import pytorch_lightning as plprint(pl._C.has_cuda) # will print True if GPU is supported, False otherwise

 一些报错解决:

import pytorch_lightning出现的报错:

 ImportError: cannot import name ‘get_num_classes’ from ‘torchmetrics.utilities.data’

根据参考  ImportError: cannot import name ‘get_num_classes’ from ‘torchmetrics.utilities.data’在虚拟环境下执行下面命令

pip uninstall torchmetricspip install torchmetrics==0.5

 然而,出现了新的报错

AttributeError: module 'distutils' has no attribute 'version'

根据参考python, torch. 遇到AttributeError: module ‘distutils‘ has no attribute ‘version‘ 报错。AttributeError: module ‘distutils‘ has no attribute ‘version‘ 解决方案

在虚拟环境下执行下面命令

pip install setuptools==59.5.0

再次尝试,报错解决

参考文章:

pytorch-lightning安装

安装 pytorch-lightning 的坑

 ImportError: cannot import name ‘get_num_classes’ from ‘torchmetrics.utilities.data’

 python, torch. 遇到AttributeError: module ‘distutils‘ has no attribute ‘version‘ 报错。

 AttributeError: module ‘distutils‘ has no attribute ‘version‘ 解决方案

AttributeError: module 'distutils' has no attribute 'version'

来源地址:https://blog.csdn.net/qq_60592939/article/details/129177520

--结束END--

本文标题: 关于安装 PyTorch-Lightning 的一些问题(GPU版)

本文链接: https://www.lsjlt.com/news/397292.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作