首页 > 解决方案 > VSCode 和 Pylance 没有正确运行模块 matplotlib

问题描述

我需要使用外部模块matplotlib。我使用带有行的命令提示符安装它pip install matplotlib。然后我添加./source"python.analysis.extraPaths"VSCode 工作台中的 settings.json 文件部分。现在,我的代码只运行了一半。它只会显示第一个的结果plt.plot(x,y)(请参见下面的代码),其余代码将不会运行。但是如果注释掉那条线,那么我会在我的终端(请看图片)终端结果中得到以下结果。如果我尝试在不调试的情况下运行代码(ctrl + F5),我会在终端中得到以下结果:C:\Users\Alejandro_DIYPC\AppData\Local\Programs\Python\Python38-32\python.exe: No module named matplotlib.__main__; 'matplotlib' is a package and cannot be directly executed. 有没有人经历过同样的事情或有类似的经历可以帮助我?谢谢你。

import matplotlib.pyplot as plt

x = [1,2,3,4]
y = [1500, 1200, 1100, 1800]
plt.plot(x,y)
plt.show()
#^this shows the x and y plot for each list respectively.
#The lists have to be numeric. but a leyend can be assigned to the values
legend = ["January","February","March","April","May","June","July","August","September","October","November","December"]
plt.xticks(x, legend)
plt.plot(x,y)
plt.show()

标签: pythonmatplotlibvisual-studio-codepylance

解决方案


推荐阅读