Matplotlib:没有名为 packaging.version 的模块

Matplotlib : No module named packaging.version

我在导入 matplotlib 时遇到错误:

File "C:\Users\barre\PycharmProjects\dogs_cats\main.py", line 23, in <module>
import matplotlib.pyplot as plt
File "C:\Users\barre\PycharmProjects\dogs_cats\venv\lib\site- 
packages\matplotlib\__init__.py",
line 105, in <module>
from packaging.version import parse as parse_version
ModuleNotFoundError: No module named 'packaging.version'

问题似乎出在 matplotlib 的 __init__.py 文件中的这一行:

line 105 : from packaging.version import parse as parse_version

我尝试使用以下命令重新安装 matplotlib,但仍然出现相同的错误:

pip uninstall matplotlib
python -m pip install --upgrade pip
pip install matplotlib

提前致谢。

我的代码:

import zipfile
import os
import cv2
import time
import random
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F

from torch.utils.data import Dataset, DataLoader

import torchvision.transforms as T
from torchvision.utils import make_grid
from torchvision.models import resnet50

from sklearn.model_selection import train_test_split

from PIL import Image

import matplotlib.pyplot as plt

with zipfile.ZipFile("C:/Users/barre/PycharmProjects/dogs_cats/dogs-vs-cats/train.zip", "r") as z:
    z.extractall(".")

with zipfile.ZipFile("C:/Users/barre/PycharmProjects/dogs_cats/dogs-vs-cats/test1.zip", "r") as z:
    z.extractall(".")

请通过(pip 安装打包)

安装打包 模块