Modulenotfounderror: no module named ‘pytorch_lightning’

In this tutorial, we will learn the solutions on how to fix the Modulenotfounderror: no module named ‘pytorch_lightning’.

The Python error no module named ‘pytorch_lightning’ occur because the python interpreter cannot find the installed pytorch_lighting in your system. Furthermore, the error occurs if the pytorch_lighting is installed yet it is not in the correct environment.

Also read: Modulenotfounderror: no module named ‘config’

What is PyTorch Lightning?

The PyTorch Lightning is the profound learning structure for professional Artificial Intelligence researchers and the machine learning engineers who used the greatest resilience without compromising performance at scale. The lightning expand as your projects go from opinion to paper or production.

How to fix the no module named ‘pytorch_lightning’?

Time needed: 3 minutes

Here are the solutions to fix the error no module named ‘pytorch_lightning’ in your windows, Anaconda

  • Solution 1: Install pytorch_lightning


    Step 1: Install the pytorch_lightning in windows
    This is the command to install the pytorch_lightning in windows:

    pip install pytorch-lightning

    If the above code is executed it will install the pytorch library.

    pip install pytorch-lightning Modulenotfounderror no module named 'pytorch_lightning'

    Step 2: Adding Imports

    import os
    import torch
    from torch import nn
    import torch.nn.functional as F
    from torchvision.datasets import MNIST
    from torch.utils.data import DataLoader, random_split
    from torchvision import transforms
    import pytorch_lightning as pl


    After you import this command it will solve the error you entered.

  • Solution 2: conda install pytorch lightning

    The following command below is the command for the installation pytorch_lightning module in Anaconda.

    conda install -c conda-forge pytorch-lightning

Conclusion

To conclude, if you encountered this error Modulenotfounderror: no module named ‘pytorch_lightning’ the above solutions is the best way to solve your error.

Leave a Comment