繁体   English   中英

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

[英]I don't know what do about about a module of python that dissapered

是的,你没看错,我一直在用 Python CrashCourse 的 matplotlib 做练习。 在我的项目目录中处理一个新文件时,当我尝试运行该文件时,它标记了我一个错误。 它告诉我模块 matplotlib 不存在,即使我已经使用它一个月了。 我试图用 matplotlib 在同一目录中运行我的旧文件,但我不能,它告诉我它不存在,这很奇怪。 我花了一整天的时间一遍又一遍地安装它,我检查了我是否为我的电脑使用了正确的版本。 当我在终端上测试它时,我没有任何问题,它告诉我它已经安装,但每次尝试在我工作的目录或任何其他目录中的 VisualStudio 中运行文件时,它告诉我该模块没有存在。

这是我的代码

import csv
from matplotlib import pyplot as plt



filename = '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 win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> ```

It shows no error. 


  [1]: https://i.stack.imgur.com/G9JXC.png

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

例子

如果要下载另一个版本的 matplotlib,则必须执行以下操作:

pip(python version) install matplotlib

前任:

pip3.7 install matplotlib

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM