最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解pyenv下使用python matplotlib模塊的問題解決

 更新時(shí)間:2018年11月29日 11:49:58   作者:YueYong  
這篇文章主要介紹了詳解pyenv下使用python matplotlib模塊的問題解決,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

先來描述一下我遇到的問題,在進(jìn)行matplotlib學(xué)習(xí)時(shí), plot.show() 總是無法成功運(yùn)行,總是會(huì)報(bào)一個(gè)錯(cuò):

RuntimeError: 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. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

其實(shí)意思很簡(jiǎn)單,就是我用的python并不是一個(gè)作為系統(tǒng)框架存在的,因?yàn)槲覟榱朔奖愎芾韕ython的版本,選擇了 pyenv 這個(gè)管理工具,是一個(gè)獨(dú)立出來的python環(huán)境。

嘗試解決無果

參考網(wǎng)上眾多的解決方法,例如以下兩個(gè)最常見的:

方法一: 添加如下兩行 代碼解決:

>>> import matplotlib
>>> matplotlib.use('TkAgg')
##在import matplotlib下的模塊,如pyplot等之前添加上面2句
>>> import matplotlib.pyplot as plt

方法二: 添加一下matplotlib的配置:

echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc

然而,以上這兩種解決方式都***無法解決我的問題***,此時(shí)出現(xiàn)了第二個(gè)錯(cuò)誤:

No module named '_tkinter'

說是找不到 tkinter 這個(gè)模塊,找了網(wǎng)上大多數(shù)方法,全都是linux系統(tǒng)下的解決方案,我真的很好奇沒有一個(gè)使用mac的用戶出現(xiàn)我這樣的問題嗎? 究其原因,是因?yàn)?,使?pyenv 獨(dú)立安裝出來的python中并沒有 tkinter 這個(gè)模塊,于是嘗試直接安裝 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

來到這,我不禁陷入了深深的思考,這個(gè) 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 就是一個(gè)利用python做GUI(圖形用戶界面),它提供各種標(biāo)準(zhǔn)的 GUI 接口項(xiàng),以利于迅速進(jìn)行高級(jí)應(yīng)用程序開發(fā)。

那么究竟去哪安裝這個(gè) tkinter 包,說實(shí)話到現(xiàn)在我也不知道如何利用 pyenv 去安裝 tkinter ,那這個(gè)問題又該怎么解決呢?

曲線救國(guó)

既然 tkinter 這個(gè)GUI庫沒用,那換個(gè)庫是不是就好了呢?結(jié)果的確和我想的一樣,在我換了一個(gè)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. 這個(gè)錯(cuò)誤的時(shí)候,在終端輸入以下命令:

echo "backend : Qt5Agg" > ~/.matplotlib/matplotlibrc

如果提示你沒有安裝 PyQt 的話,你就需要執(zhí)行

brew install pyqt

然后在執(zhí)行

pip install PyQt5

這時(shí)候在運(yùn)行你的代碼就可以了。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

集安市| 巨鹿县| 邯郸县| 阿克苏市| 嫩江县| 岱山县| 尉氏县| 林州市| 阜宁县| 皋兰县| 始兴县| 宁晋县| 普陀区| 抚松县| 阿荣旗| 大庆市| 德昌县| 宾川县| 河北区| 阜康市| 陵川县| 焦作市| 博兴县| 仁布县| 锡林浩特市| 灵丘县| 江都市| 嘉义县| 朝阳区| 隆化县| 台南县| 醴陵市| 泗水县| 大新县| 鞍山市| 金沙县| 武山县| 巴林左旗| 淮北市| 长岭县| 衡东县|