是的,您沒有看錯,我一直在使用 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 版本的位置,然后單擊它進行更改。
如果你想下載另一個版本的 matplotlib,你必須這樣做:
pip(python version) install matplotlib
前任:
pip3.7 install matplotlib
添加回答
舉報
0/150
提交
取消