安装PyTorch-Lightning踩坑

官网地址:

PyTorch

PyTorch-Lightning

安装PyTorch-Lightning

1、不能直接使用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

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

pip install pytorch-lightning==版本名

或:

conda install lightning==版本名 -c conda-forge

验证PyTorch和PyTorch-Lightning版本

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

import torch
print(torch.__version__)

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

import pytorch_lightning as pl
print(pl.__version__)

验证GPU是否能用

import torch

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

你可能感兴趣的:(环境搭建,pytorch,人工智能,python)