我写了一个基本的绘图代码,然后以某种方式无法在VS代码上运行它
我删除了python本身和VS代码,然后再次下载了它们,但问题仍未解决。
import matplotlib.pyplot as plt
x = [1,2,3]
y = [4,5,6]
plt.plot(x,y)
plt.show()
Traceback (most recent call last):
File "c:/Users/xxx/Desktop/Cmpt Physics/dreams.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\__init__.py", line 138, in <module>
from . import cbook, rcsetup
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\rcsetup.py", line 24, in <module>
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\fontconfig_pattern.py", line 18, in <module>
from pyparsing import (Literal, ZeroOrMore, Optional, Regex, StringEnd,
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\pyparsing.py", line 104, in <module>
import copy
File "c:\Users\xxx\Desktop\Cmpt Physics\copy.py", line 5, in <module>
from pylab import plot,show,grid
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\pylab.py", line 218, in <module>
from matplotlib.dates import (
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\dates.py", line 156, in <module>
from matplotlib import rcParams
ImportError: cannot import name 'rcParams' from 'matplotlib' (C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\__init__.py)
知道为什么会这样吗?
最佳答案
似乎您正在从包含名为copy
的模块的目录中运行代码,该模块正在从stdlib中屏蔽copy
模块(c:\Users\xxx\Desktop\Cmpt Physics\copy.py
似乎是罪魁祸首)。将该文件重命名为与stdlib中的名称不同的名称,它应该可以解决该问题。
通常,对stdlib进行阴影处理会导致类似这样的奇怪结果:将stdlib乱序插入模块或错误的模块,并使事情以奇怪的方式破坏。
关于python - 为什么Matplotlib在VSCode上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58206459/