Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
134 views
in Technique[技术] by (71.8m points)

python - Attribute error whenever I import matplotlib

Everytime I import matplotlib into my python programs I get this error (here the program is just one line "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 programsPython38libsite-packagesmatplotlib\__init__.py", line 94,
 in <module>      
 import logging   
File "D:Other programsPython38liblogging\__init__.py", line 28, in <module>    
     from string import Template   
File "D:programspythonstring.py", line 1, in <module>    
     import matplotlib.pyplot as plt   
File "D:Other programsPython38libsite-packagesmatplotlibpyplot.py", line 36, in <module>    
import matplotlib.colorbar   
File "D:Other programsPython38libsite-packagesmatplotlibcolorbar.py", line 40, in <module>    
import matplotlib.artist as martist   
File "D:Other programsPython38libsite-packagesmatplotlibartist.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)

I cannot find any logging.py anywhere. Is this some sort of bug in the lates version of matplotlib?

question from:https://stackoverflow.com/questions/65642390/attribute-error-whenever-i-import-matplotlib

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

your script D:programspythonstring.py, where you try to import matplotlib.pyplot as plt is named string.py and it interferes with string module from standard library. Rename that file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...