填坑(python3.6)(matplotlib) AttributeError: ‘version_info’ object has no attribute ‘__version__’

python3.6 import matplotlib pyparsing 包版本获取报错_m0_37806296的博客-CSDN博客

根据错误提示,找到你所对应的文件........\Lib\site-packages\pyparsing_init_.py

修改class version_info(NamedTuple)函数

原函数为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class version_info(NamedTuple):
    major: int
    minor: int
    micro: int
    releaselevel: str
    serial: int

    @property
    def __version__(self):
        return "{}.{}.{}".format(self.major, self.minor, self.micro) + (
            "{}{}{}".format(
                "r" if self.releaselevel[0] == "c" else "",
                self.releaselevel[0],
                self.serial,
            ),
            "",
        )[self.releaselevel == "final"]

    def __str__(self):
        return "{} {} / {}".format(__name__, self.__version__, __version_time__)

    def __repr__(self):
        return "{}.{}({})".format(
            __name__,
            type(self).__name__,
            ", ".join("{}={!r}".format(*nv) for nv in zip(self._fields, self)),
        )

修改为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class version_info():
    def __init__(self, major: int, minor: int, micro: int, releaselevel: str, serial: int):
        self.major = major
        self.minor = minor
        self.micro = micro
        self.releaselevel = releaselevel
        self.serial = serial

    @property
    def __version__(self):
        return "{}.{}.{}".format(self.major, self.minor, self.micro) + (
            "{}{}{}".format(
                "r" if self.releaselevel[0] == "c" else "",
                self.releaselevel[0],
                self.serial,
            ),
            "",
        )[self.releaselevel == "final"]

    def __str__(self):
        return "{} {} / {}".format(__name__, self.__version__, __version_time__)

    def __repr__(self):
        return "{}.{}({})".format(
            __name__,
            type(self).__name__,
            ", ".join("{}={!r}".format(*nv) for nv in zip(self._fields, self)),
        )