方式一:通過cmd方式安裝
進入Python的安裝目錄下,我的是在D:\Python。輸入python -m pip install -U pip setuptools
2.輸入python -m pip install matplotlib
3.檢查是否已經安裝成功。輸入python -m pip list
成功安裝。默認安裝在D:\Python\Lib\site-packages
方式二:通過下載matplotlib進行安裝。
進入matplotlib官網。
2.點擊PyPI
3.點擊Downloadfiles
查看你的Python安裝版本,下載對應的.whl。我的是64位3.8版本
4.將其放入D:\Python\Scripts路徑。
由於我的已經存在。顯示的是already satisfied。正常的話應該是successfully。
由於我的已經存在。顯示的是already satisfied。正常的話應該是successfully。
由於我的已經存在。顯示的是already satisfied。正常的話應該是successfully。
安裝好matplotlib但是import時仍然報錯問題處理方式一:
點擊File的settings.
點擊+號。
想安裝什麼就安裝什麼。直接搜。
解決方案二:
pip會將下載的第三方包存放在以下路徑:[your path]\Python\Lib\site-packages\中,在這個文件夾下,找到我們要引用的包,複製到:[使用解釋器路徑]\Lib\site-packages\下,即可使用。如圖。
解決方案三:
重新建項目,創建的時候勾選「inherit global site-packages」,即可解決。詳情見下圖
到此問題全部解決。測試代碼:
import matplotlib.pyplot as ymdimport numpy as nuimport matplotlibymd.subplot(212)group = 12months = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)index = nu.arange(group)width = 0.35opacity = 0.4rects = ymd.bar(index, months, width, alpha=opacity, color='b', label='months')ymd.xlabel('month')ymd.ylabel('days')ymd.xticks(index + width, ('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'))ymd.ylim(0, 32)ymd.show()