AttributeError: module ‘configparser‘ has no attribute ‘SafeConfigParser‘. Did you mean: ‘RawConfigP

文章讲述了在使用pip安装matplotlib3.3.3时遇到的错误,原因是versioneer.py中的SafeConfigParser被Python3中的ConfigParser取代。解决方法包括升级到最新版本的matplotlib,修改requirements.txt,或者手动修复versioneer.py文件。
摘要由CSDN通过智能技术生成

问题

在pip安装时,出现

Collecting matplotlib==3.3.3 (from -r requirements.txt (line 20))
  Downloading matplotlib-3.3.3.tar.gz (37.9 MB)
     ---------------------------------------- 37.9/37.9 MB 727.1 kB/s eta 0:00:00
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\lutao\AppData\Local\Temp\pip-install-epd8fs5d\matplotlib_6c900e11b6454be496de6443b6d0a51e\setup.py", line 52, in <module>
          __version__ = versioneer.get_version()
                        ^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\lutao\AppData\Local\Temp\pip-install-epd8fs5d\matplotlib_6c900e11b6454be496de6443b6d0a51e\versioneer.py", line 1410, in get_version
          return get_versions()["version"]
                 ^^^^^^^^^^^^^^
        File "C:\Users\lutao\AppData\Local\Temp\pip-install-epd8fs5d\matplotlib_6c900e11b6454be496de6443b6d0a51e\versioneer.py", line 1344, in get_versions
          cfg = get_config_from_root(root)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\lutao\AppData\Local\Temp\pip-install-epd8fs5d\matplotlib_6c900e11b6454be496de6443b6d0a51e\versioneer.py", line 401, in get_config_from_root
          parser = configparser.SafeConfigParser()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      AttributeError: module 'configparser' has no attribute 'SafeConfigParser'. Did you mean: 'RawConfigParser'?
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

原因

安装matplotlib版本3.3.3时,setup.py脚本执行失败。错误信息提示在versioneer.py文件中,configparser模块没有SafeConfigParser属性。这是因为在Python 3中,SafeConfigParser已经被重命名为ConfigParser。

Versioneer 与现代 Python 不兼容,需要更新代码。

解决

升级matplotlib到一个更新的版本:较新的版本可能已经修复了这个兼容性问题。尝试安装最新版本的matplotlib,或者至少是一个已知兼容Python 3的版本。

修改requirements.txt:在requirements.txt文件中更新matplotlib的版本。例如,如果您使用的是Python 3,您可以尝试将matplotlib版本改为3.4或更高

手动修复问题:如果您由于某些原因需要坚持使用matplotlib的3.3.3版本,并且不能升级,您可以尝试编辑出错的versioneer.py文件,将所有的SafeConfigParser替换为ConfigParser。但是,请注意,这种方法可能会引入其他兼容性问题,且不是推荐的做法。

ref

https://github.com/pydata/pandas-datareader/issues/969

  • 15
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值