這篇文章將為大家詳細(xì)講解有關(guān)怎么在pyenv中使用matplotlib模塊,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
方法一: 添加如下兩行 代碼解決:
>>> import matplotlib >>> matplotlib.use('TkAgg') ##在import matplotlib下的模塊,如pyplot等之前添加上面2句 >>> import matplotlib.pyplot as plt
方法二: 添加一下matplotlib的配置:
echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
然而,以上這兩種解決方式都***無法解決我的問題***,此時出現(xiàn)了第二個錯誤:
No module named '_tkinter'
說是找不到 tkinter 這個模塊,找了網(wǎng)上大多數(shù)方法,全都是linux系統(tǒng)下的解決方案,我真的很好奇沒有一個使用mac的用戶出現(xiàn)我這樣的問題嗎? 究其原因,是因為,使用 pyenv 獨(dú)立安裝出來的python中并沒有 tkinter 這個模塊,于是嘗試直接安裝 tkinter ,結(jié)果竟然提示沒有發(fā)現(xiàn) tkinter 包!
pip3 install tkinter Collecting tkinter Could not find a version that satisfies the requirement tkinter (from versions: ) No matching distribution found for tkinter
來到這,我不禁陷入了深深的思考,這個 tkinter 到底是何方神圣,去了Python社區(qū):https://docs.python.org/3/library/tkinter.html ,這才懂了他是啥玩意:
The tkinter package (“Tk interface”) is the standard Python interface to the Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, as well as on Windows systems. (Tk itself is not part of Python; it is maintained at ActiveState.) Running python -m tkinter from the command line should open a window demonstrating a simple Tk interface, letting you know that tkinter is properly installed on your system, and also showing what version of Tcl/Tk is installed, so you can read the Tcl/Tk documentation specific to that version.
說白了, tkinter 就是一個利用python做GUI(圖形用戶界面),它提供各種標(biāo)準(zhǔn)的 GUI 接口項,以利于迅速進(jìn)行高級應(yīng)用程序開發(fā)。
那么究竟去哪安裝這個 tkinter 包,說實話到現(xiàn)在我也不知道如何利用 pyenv 去安裝 tkinter ,那這個問題又該怎么解決呢?
曲線救國
既然 tkinter 這個GUI庫沒用,那換個庫是不是就好了呢?結(jié)果的確和我想的一樣,在我換了一個GUI庫之后,他的確成功了。 具體操作如下: 在出現(xiàn) Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. 這個錯誤的時候,在終端輸入以下命令:
echo "backend : Qt5Agg" > ~/.matplotlib/matplotlibrc
如果提示你沒有安裝 PyQt 的話,你就需要執(zhí)行
brew install pyqt
然后在執(zhí)行
pip install PyQt5
這時候在運(yùn)行你的代碼就可以了。
關(guān)于怎么在pyenv中使用matplotlib模塊就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
分享標(biāo)題:怎么在pyenv中使用matplotlib模塊-創(chuàng)新互聯(lián)
轉(zhuǎn)載注明:http://www.chinadenli.net/article24/gsgje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、網(wǎng)站收錄、網(wǎng)站設(shè)計公司、服務(wù)器托管、網(wǎng)站排名、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容