我正在使用Mac Yosemite和Anaconda的Python 3.4發行版。每當我做matplotlib掛在mac osx上並且不顯示圖形
import matplotlib.pyplot as plt
...
plt.semilogy(x, y)
plt.show()
一個空的窗口彈出在掛起狀態。
我看到一個類似的帖子:Matplotlib not showing up in Mac OSX,其中建議使用
sudo port install py25-matplotlib +cairo+gtk2
sudo port install py26-matplotlib +cairo+gtk2
由於我使用python 3.4,我試圖
sudo port install py34-matplotlib +cairo+gtk2
安裝了罰款,但是當我試圖import matplotlib
上PyCharm中的Python控制檯,我得到以下錯誤:
Backend GTKCairo is interactive backend. Turning interactive mode on.
Failed to enable GUI event loop integration for 'gtk'
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_console_utils.py", line 498, in do_enable_gui
enable_gui(guiname)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_ipython/inputhook.py", line 479, in enable_gui
return gui_hook(app)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_ipython/inputhook.py", line 227, in enable_gtk
from pydev_ipython.inputhookgtk import create_inputhook_gtk
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_ipython/inputhookgtk.py", line 19, in <module>
import gtk, gobject
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named 'gtk'
可能是什麼問題?
我無法找到內PyCharm任何
gtk
模塊,但我發現PyGTK
,PyGTKCodeBuffer
,PyGTKImageView
,等是否有任何網站爲gtk
模塊?
*編輯*
我通過在matplotlibrc
文件中添加Interactive : True
解決了這個問題。
PyGTK是Python gtk模塊的來源。嘗試安裝一個,看看它是否修復它。 – mprat
你應該回答你自己的問題,因爲你找到了解決方案,我幾乎錯過了你的編輯,包含你做了什麼 – codebox