我写了一个基本的绘图代码,然后以某种方式程序无法运行它在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)
知道为什么会这样吗?
答案 0 :(得分:3)
似乎您正在从包含名为copy
的模块的目录中运行代码,该模块正在从stdlib中遮盖copy
模块(c:\Users\xxx\Desktop\Cmpt Physics\copy.py
似乎是罪魁祸首)。将该文件重命名为与stdlib中的名称不同的名称,它将解决该问题。
通常情况下,对stdlib进行阴影处理会导致奇怪的结果,例如,它会使模块乱序或错误的模块插入,并使事情以奇怪的方式破坏。