为了账号安全,请及时绑定邮箱和手机立即绑定

我不知道如何处理消失的 python 模块

我不知道如何处理消失的 python 模块

拉丁的传说 2023-06-20 15:51:17
是的,您没有看错,我一直在使用 Python CrashCourse 中的 matplotlib 进行练习。在我的项目目录中处理一个新文件时,当我尝试运行该文件时,它给我标记了一个错误。它告诉我模块 matplotlib 不存在,即使我已经使用它一个月了。我试图在与 matplotlib 相同的目录中运行我的旧文件,但我不能,它告诉我它不存在,这很奇怪。我花了一整天的时间一遍又一遍地安装它,我检查了我是否为我的电脑使用了正确的版本。当我在终端上测试它时我没有任何问题,它告诉我它已经安装但是每次尝试在我工作的目录或任何其他目录中的 VisualStudio 中运行文件时它告诉我该模块没有存在。这是我的代码import csvfrom matplotlib import pyplot as pltfilename = 'sitka_weather_07-2014.csv'with open(filename) as f:    reader = csv.reader(f)    #We save the first line  using a csv function    header_row = next(reader)        '''#We use enumerate() to put an index on each value    for index, column_header in enumerate(header_row):        print(index, column_header)'''    #We get the high temperatures        highs = []    for row in reader: #We continue in the second line        highs.append(int(row[1]))    #print(highs)    #Plot data    fig = plt.figure(dpi=128, figsize=(10,6))    plt.plot(highs, c='red')    #Format plot    plt.title("Daily high temperatures, July 2014", fontsize=24)    plt.xlabel('', fontsize=16)    plt.ylabel('Temperature (F)', fontsize=16)    plt.tick_param(axis='both', which='major', labelsize=16)    plt.show() [![在此处输入图片描述][1]][1]我测试了它打字Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> import matplotlib>>> ```It shows no error.   [1]: https://i.stack.imgur.com/G9JXC.png
查看完整描述

1 回答

?
幕布斯6054654

TA贡献1876条经验 获得超7个赞

您不小心在可视代码中切换了 python 版本。要解决此问题,您必须转到右下角显示 python 版本的位置,然后单击它进行更改。

//img1.sycdn.imooc.com//64915aa70001c42d02470226.jpg

如果你想下载另一个版本的 matplotlib,你必须这样做:

pip(python version) install matplotlib

前任:

pip3.7 install matplotlib


查看完整回答
反对 回复 2023-06-20
  • 1 回答
  • 0 关注
  • 93 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信