【问题标题】:Attribute error whenever I import matplotlib每当我导入 matplotlib 时出现属性错误
【发布时间】:2021-01-09 12:03:07
【问题描述】:

每次我将 matplotlib 导入我的 python 程序时,我都会收到这个错误(这里程序只有一行“import matplotlib.pyplot as plt”):

 Traceback (most recent call last):   
File "string.py", line 1, in \<module>  
import matplotlib.pyplot as plt   
File "D:\Other programs\Python38\lib\site-packages\matplotlib\__init__.py", line 94,
 in \<module>      
 import logging   
File "D:\Other programs\Python38\lib\logging\__init__.py", line 28, in \<module>    
     from string import Template   
File "D:\programs\python\string.py", line 1, in \<module>    
     import matplotlib.pyplot as plt   
File "D:\Other programs\Python38\lib\site-packages\matplotlib\pyplot.py", line 36, in \<module>    
import matplotlib.colorbar   
File "D:\Other programs\Python38\lib\site-packages\matplotlib\colorbar.py", line 40, in \<module>    
import matplotlib.artist as martist   
File "D:\Other programs\Python38\lib\site-packages\matplotlib\artist.py", line 17, in \<module>    
_log = logging.getLogger(__name__)   
AttributeError: partially initialized module 'logging' has no attribute 'getLogger' (most likely
 due to a circular import)

我在任何地方都找不到任何 logging.py。这是 matplotlib 最新版本中的某种错误吗?

【问题讨论】:

    标签: python python-3.x matplotlib


    【解决方案1】:

    您的脚本D:\programs\python\string.py,您尝试在其中尝试import matplotlib.pyplot as plt 被命名为string.py,它会干扰标准库中的string 模块。重命名该文件。

    【讨论】:

      猜你喜欢
      • 2021-04-26
      • 1970-01-01
      • 2020-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 2015-03-04
      • 1970-01-01
      相关资源
      最近更新 更多