sktime / pytorch-forecasting

Time series forecasting with PyTorch
https://pytorch-forecasting.readthedocs.io/
MIT License
3.99k stars 631 forks source link

No module named 'pytorch_lightning.core.lightning' #1319

Open jambudipa opened 1 year ago

jambudipa commented 1 year ago

Expected behavior

I expect my code to compile, but I get an error.

Actual behavior

I get the error:

No module named 'pytorch_lightning.core.lightning'

I installed using the conda command on the home page of GitHub:

conda install pytorch-forecasting pytorch -c pytorch>=1.7 -c conda-forge

...although I had to remove the >=1.7 because it told me that was a syntax error.

The error is thrown in anaconda3/envs/pytorch/lib/python3.11/site-packages/pytorch_forecasting/models/deepar/__init__.py, and it seems my version of the code does not in any way correspond to what is in the repo, starting instead like this:

"""
`DeepAR: Probabilistic forecasting with autoregressive recurrent networks
<https://www.sciencedirect.com/science/article/pii/S0169207019301888>`_
which is the one of the most popular forecasting algorithms and is often used as a baseline
"""
from copy import copy, deepcopy
from typing import Any, Dict, List, Tuple, Union

import matplotlib.pyplot as plt
from matplotlib.pyplot import plot_date
import numpy as np
import pandas as pd
from pytorch_lightning.core.lightning import LightningModule
import torch
import torch.distributions as dists
import torch.nn as nn
from torch.nn.utils import rnn
from torch.utils.data.dataloader import DataLoader

I must tell you that I am a Python newbie 😇 although 42 years of programming experience!

How do I pull the code in the right way??

maayange17 commented 1 year ago

I have this problem too!

jambudipa commented 1 year ago

Is it possible to install from GitHub?

nigelparsad commented 1 year ago

I also have this problem.

Coopez commented 1 year ago

I had this problem too. Didn't find a solution, so I looked into where the import is called: For me that waspytorch_forecasting\models\deepar\__init__.py line 13. The import is not used in the file, so I just deleted the line.

ilknurozcelik commented 1 year ago

I had the same problem. I solved the issue by applying the method mentioned by Coopez. It worked for me.

havanoname commented 1 year ago

I have same problem, I found some solutions to the problem. Recommend: First, PyTorch-Forecasting does not support python3.11, please install python3.8-3.10. Second, if your lightning or pytorch lightning is 2.0 or above, please Update to pytorch-forecasting 1.0.0 (use pip install pytorch-forecasting, conda install is still version 0.10.2). Anyway, please make sure that the python version is within 3.10, and that only pytorch-forecasting 1.0 supports lightning 2.0.

Other way: There may be some problems

  1. As @Coopez said, deleted the line, but maybe this module will be used later.
  2. Replace this line with: from pytorch_lightning.core.module import LightningModule, because pytorch_lightning 2.0 seems to have replaced the core.lightning with core.module
nmuralid1 commented 1 year ago

The solution suggested by @havanoname (i.e., downgrading to python version 3.10) and using pytorch lightning installed with pip) worked for me. Post the downgrade to a conda environment with python version 3.10 (with pytorch installed) all I had to do was install the pytorch-forecasting library with pip and the tutorials in pytorch-forecasting seemed to start working (i.e., I was no longer facing the pytorch lightning errors).

amrirasyidi commented 1 year ago

I have same problem, I found some solutions to the problem. Recommend: First, PyTorch-Forecasting does not support python3.11, please install python3.8-3.10. Second, if your lightning or pytorch lightning is 2.0 or above, please Update to pytorch-forecasting 1.0.0 (use pip install pytorch-forecasting, conda install is still version 0.10.2). Anyway, please make sure that the python version is within 3.10, and that only pytorch-forecasting 1.0 supports lightning 2.0.

Other way: There may be some problems

  1. As @Coopez said, deleted the line, but maybe this module will be used later.
  2. Replace this line with: from pytorch_lightning.core.module import LightningModule, because pytorch_lightning 2.0 seems to have replaced the core.lightning with core.module

This also works on my case

Lareina2441 commented 1 year ago

same problem. image

susmera-joseph commented 11 months ago

pytorch-forecasting 1.0.0 pytorch-lightning 2.0.0 pytorch_optimizer 2.12.0 torch 2.1.1 torchmetrics 1.2.0 Above are torch versions installed in my conda env. with python 3.8.18. I am getting below error while trying to set up https://pytorch-forecasting.readthedocs.io/en/stable/tutorials/stallion.html in my Anaconda Env in Mac ImportError: cannot import name 'Prediction' from 'pytorch_forecasting.models.base_model' error. I am a beginner in python. looking forward for help.

JuanGonzalezU commented 9 months ago

With conda, pytorch-forecasting is not updated, use pip install pytorch-forecasting. I had to then also install fastparquet and pyarrow with conda, and now it works :)

KarimABOUSSELHAM commented 5 months ago

I have same problem, I found some solutions to the problem. Recommend: First, PyTorch-Forecasting does not support python3.11, please install python3.8-3.10. Second, if your lightning or pytorch lightning is 2.0 or above, please Update to pytorch-forecasting 1.0.0 (use pip install pytorch-forecasting, conda install is still version 0.10.2). Anyway, please make sure that the python version is within 3.10, and that only pytorch-forecasting 1.0 supports lightning 2.0.

Other way: There may be some problems

  1. As @Coopez said, deleted the line, but maybe this module will be used later.
  2. Replace this line with: from pytorch_lightning.core.module import LightningModule, because pytorch_lightning 2.0 seems to have replaced the core.lightning with core.module

Great suggestion. I followed the instructions after creation of a virtual environment with python 3.10.0 and it worked just perfect. Thanks.

lijiandao commented 3 months ago

建议使用python 3.8 pytorch_lightning 建议降级处理,我成功的解决了这个问题,就是通过不断的尝试安装更低的版本。比如pytorch_lightning==1.3.8 或者是pytorch_lightning==2.1