ModuleNotFoundError:Windows 和 Jupyter 上没有名为“matplotlib.axes._subplots”的模块

问题描述 投票:0回答:1

我希望这个问题不是重复的。 其他威胁中的答案对我没有帮助。

我已经安装了

Python 3.12

在 Windows 笔记本电脑/笔记本电脑上(Windows 11 Home,10.0.22631,在 Dell G15 5520,x64 上)。
对于我的项目,我使用
Jupyter

我在 PATH 中有
pip
和 Python(pip-commands 和 pip-jupyter-commands 运行良好)。

到目前为止,我在我的项目中使用了以下软件包:

from timeseries_generator import LinearTrend, Generator, WhiteNoise, RandomFeatureFactor #(installed directly from GIT with: pip install git+https://github.com/Nike-Inc/timeseries-generator.git, or pip install jupyter git+https://github.com/Nike-Inc/timeseries-generator.git
import pandas as pd
import matplotlib #(because of the error I tried to install seperately)
import keras #(for machine learning later on)

当我运行代码(来自 timeseriesgenerator 的示例,只是为了尝试

timesieries_generator
)时,我收到以下错误:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[3], line 1
----> 1 from timeseries_generator import LinearTrend, Generator, WhiteNoise, RandomFeatureFactor
      2 import pandas as pd
      3 import matplotlib

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\timeseries_generator\__init__.py:1
----> 1 from .base_factor import BaseFactor
      2 from .errors import *
      3 from .generator import Generator

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\timeseries_generator\base_factor.py:5
      2 from typing import List, Dict, Optional, Union, Tuple
      4 from matplotlib.figure import Figure
----> 5 from matplotlib.axes._subplots import SubplotBase
      6 from matplotlib.pyplot import subplots
      7 from pandas import DataFrame, date_range, DatetimeIndex

ModuleNotFoundError: No module named 'matplotlib.axes._subplots'

所以看来这是

timeseries_generator
的问题。

我尝试了很多来自互联网的建议(只安装了一个Python,更新了所有内容,单独安装matplotlib,甚至按照这里的建议直接将其安装在jupyter中......)。

当我安装

matplotlib
pip install matplotlib
pip install jupyter matplotlib
)时,我收到以下请求:

Requirement already satisfied: types-python-dateutil>=2.8.10 in c:PATH-To-Python\python312\lib\site-packages (from arrow>=0.15.0->isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter) (2.9.0.20240316)  

各种形式。

Jupyter 中的 python 代码如下所示:

from timeseries_generator import LinearTrend, Generator, WhiteNoise, RandomFeatureFactor
import pandas as pd
import matplotlib
import keras

# setting up a linear trend
lt = LinearTrend(coef=2.0, offset=1., col_name="my_linear_trend")
g = Generator(factors={lt}, features=None, date_range=pd.date_range(start="01-01-2020", end="01-20-2020"))
g.generate()
g.plot()

# update by adding some white noise to the generator
wn = WhiteNoise(stdev_factor=0.05)
g.update_factor(wn)
g.generate()
g.plot()

我想获得一些用于机器学习的合成图(随机图/图)。

我希望你能帮助我。 谢谢您提前的答复!

python matplotlib jupyter modulenotfounderror
1个回答
0
投票

我认为问题在于 timeseries-generator 包与最新版本的 Matplotlib 不兼容。您需要将 Matplotlib 降级到仍包含

matplotlib.axes._subplots
模块的版本 - 似乎 v3.6.3 是最后一个兼容版本,所以这样做:

pip install matplotlib==3.6.3
© www.soinside.com 2019 - 2024. All rights reserved.